diff options
Diffstat (limited to '')
-rw-r--r-- | src/directory.c | 2 | ||||
-rw-r--r-- | src/update.c | 60 | ||||
-rw-r--r-- | src/update.h | 2 |
3 files changed, 15 insertions, 49 deletions
diff --git a/src/directory.c b/src/directory.c index 38f32c271..83835c15a 100644 --- a/src/directory.c +++ b/src/directory.c @@ -506,7 +506,7 @@ int traverseAllIn(const char *name, void directory_init(void) { music_root = newDirectory(NULL, NULL); - exploreDirectory(music_root); + updateDirectory(music_root); stats.numberOfSongs = countSongsIn(NULL); stats.dbPlayTime = sumSongTimesIn(NULL); } diff --git a/src/update.c b/src/update.c index 6c21444b6..4a2c11e94 100644 --- a/src/update.c +++ b/src/update.c @@ -169,7 +169,7 @@ addSubDirectoryToDirectory(Directory * directory, subDirectory = newDirectory(name, directory); directory_set_stat(subDirectory, st); - if (exploreDirectory(subDirectory) != UPDATE_RETURN_UPDATED) { + if (updateDirectory(subDirectory) != UPDATE_RETURN_UPDATED) { freeDirectory(subDirectory); return UPDATE_RETURN_NOUPDATE; } @@ -207,8 +207,6 @@ addToDirectory(Directory * directory, const char *name) return UPDATE_RETURN_ERROR; } -static enum update_return updateDirectory(Directory * directory); - static enum update_return updateInDirectory(Directory * directory, const char *name) { @@ -250,48 +248,9 @@ static int skip_path(const char *path) return (path[0] == '.' || strchr(path, '\n')) ? 1 : 0; } -enum update_return exploreDirectory(Directory * directory) -{ - DIR *dir; - const char *dirname = getDirectoryPath(directory); - struct dirent *ent; - char path_max_tmp[MPD_PATH_MAX]; - enum update_return ret = UPDATE_RETURN_NOUPDATE; - - DEBUG("explore: attempting to opendir: %s\n", dirname); - - dir = opendir(opendir_path(path_max_tmp, dirname)); - if (!dir) - return UPDATE_RETURN_ERROR; - - DEBUG("explore: %s\n", dirname); - - while ((ent = readdir(dir))) { - char *utf8; - if (skip_path(ent->d_name)) - continue; - - utf8 = fs_charset_to_utf8(path_max_tmp, ent->d_name); - if (!utf8) - continue; - - DEBUG("explore: found: %s (%s)\n", ent->d_name, utf8); - - if (directory->path) - utf8 = pfx_dir(path_max_tmp, utf8, strlen(utf8), - dirname, strlen(dirname)); - if (addToDirectory(directory, path_max_tmp) == - UPDATE_RETURN_UPDATED) - ret = UPDATE_RETURN_UPDATED; - } - - closedir(dir); - - return ret; -} - -static enum update_return updateDirectory(Directory * directory) +enum update_return updateDirectory(Directory * directory) { + int was_empty = directory_is_empty(directory); DIR *dir; const char *dirname = getDirectoryPath(directory); struct dirent *ent; @@ -309,7 +268,8 @@ static enum update_return updateDirectory(Directory * directory) if (!dir) return UPDATE_RETURN_ERROR; - if (removeDeletedFromDirectory(path_max_tmp, directory) > 0) + if (!was_empty && + removeDeletedFromDirectory(path_max_tmp, directory) > 0) ret = UPDATE_RETURN_UPDATED; while ((ent = readdir(dir))) { @@ -324,8 +284,14 @@ static enum update_return updateDirectory(Directory * directory) if (directory->path) utf8 = pfx_dir(path_max_tmp, utf8, strlen(utf8), dirname, strlen(dirname)); - if (updateInDirectory(directory, path_max_tmp) > 0) - ret = UPDATE_RETURN_UPDATED; + if (was_empty) { + if (addToDirectory(directory, path_max_tmp) == + UPDATE_RETURN_UPDATED) + ret = UPDATE_RETURN_UPDATED; + } else { + if (updateInDirectory(directory, path_max_tmp) > 0) + ret = UPDATE_RETURN_UPDATED; + } } closedir(dir); diff --git a/src/update.h b/src/update.h index 132ef175d..4e59e39b1 100644 --- a/src/update.h +++ b/src/update.h @@ -30,7 +30,7 @@ enum update_return { int isUpdatingDB(void); -enum update_return exploreDirectory(Directory * directory); +enum update_return updateDirectory(Directory * directory); /* * returns the non-negative update job ID on success, |