From 599d5820bce424625e54e2486191437a012ff1dc Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 4 Jan 2009 17:26:07 +0100 Subject: update: moved code to directory_exists(), fix typo Reverse the condition: delete directories which don't exist anymore. This typo caused a slowdown during partial database update. --- src/update.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/update.c b/src/update.c index 853aa9d8d..eaffebb10 100644 --- a/src/update.c +++ b/src/update.c @@ -190,6 +190,23 @@ delete_song_if_removed(struct song *song, void *_data) return 0; } +static bool +directory_exists(const struct directory *directory) +{ + char *path_fs; + bool exists; + + path_fs = map_directory_fs(directory); + if (path_fs == NULL) + /* invalid path: cannot exist */ + return false; + + exists = g_file_test(path_fs, G_FILE_TEST_IS_DIR); + g_free(path_fs); + + return exists; +} + static void removeDeletedFromDirectory(struct directory *directory) { @@ -198,17 +215,9 @@ removeDeletedFromDirectory(struct directory *directory) struct delete_data data; for (i = dv->nr; --i >= 0; ) { - char *path_fs; - bool is_dir; - - path_fs = map_directory_fs(dv->base[i]); - if (path_fs == NULL) + if (directory_exists(dv->base[i])) continue; - is_dir = g_file_test(path_fs, G_FILE_TEST_IS_DIR); - g_free(path_fs); - if (!is_dir) - continue; g_debug("removing directory: %s", dv->base[i]->path); dirvec_delete(dv, dv->base[i]); modified = true; -- cgit v1.2.3