diff options
author | Max Kellermann <max@duempel.org> | 2008-10-08 10:48:55 +0200 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-10-11 19:21:47 -0700 |
commit | b5d3970c075987d7439e2b60ea043606f46a3bab (patch) | |
tree | 18dbef270a5df1c0a6c20ab63f906f871b873ec4 | |
parent | 7b5c84829768b8ee2ac0ad131045736afc586643 (diff) | |
download | mpd-b5d3970c075987d7439e2b60ea043606f46a3bab.tar.gz mpd-b5d3970c075987d7439e2b60ea043606f46a3bab.tar.xz mpd-b5d3970c075987d7439e2b60ea043606f46a3bab.zip |
update: merged exploreDirectory() into updateDirectory()
exploreDirectory() duplicates some code in updateDirectory(). Merge
both functions, and use directory_is_empty() to determine whether
update or explore mode should be used.
-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, |