diff --git a/code/application/source/sf_app/code/source/storeMng/sf_storeMng.c b/code/application/source/sf_app/code/source/storeMng/sf_storeMng.c index d14b4183e..53f9108bd 100644 --- a/code/application/source/sf_app/code/source/storeMng/sf_storeMng.c +++ b/code/application/source/sf_app/code/source/storeMng/sf_storeMng.c @@ -669,6 +669,34 @@ static void trave_file(char* path) return; } +int sf_is_directory_empty(const char *path) +{ + DIR *dir = opendir(path); + + if (dir == NULL) { + MLOGE("Error opening directory"); + return -1; + } + + struct dirent *entry; + int count = 0; + + while ((entry = readdir(dir)) != NULL) { + + if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { + count++; + break; + } + } + + closedir(dir); + + if (count == 0) { + return 1; + } else { + return 0; + } +} int sf_dcf_resort_min(void) { @@ -706,6 +734,13 @@ int sf_dcf_resort_min(void) MLOGD("DirKey:%d,FileKey:%d\n", gLastDirKey, gLastFileKey); if(gLastFileKey <= MAX_DCF_FILE_NUM) { + sprintf(sTmp,"%s/%d%s",sRootPath,gLastDirKey,DCF_DIR_NAME); + if(sf_is_directory_empty(sTmp)) + { + MLOGD("Will Delete Dir:%s\n", sTmp); + remove(sTmp); + system("sync"); + } gLastDirKey = i; MLOGD("DirKey:%d,FileKey:%d\n", gLastDirKey, gLastFileKey); return 0;