diff options
-rw-r--r-- | src/update.c | 51 |
1 files changed, 12 insertions, 39 deletions
diff --git a/src/update.c b/src/update.c index e24702749..55740bfc4 100644 --- a/src/update.c +++ b/src/update.c @@ -187,35 +187,6 @@ addSubDirectoryToDirectory(struct directory *directory, } static enum update_return -addToDirectory(struct directory *directory, const char *name) -{ - struct stat st; - - if (myStat(name, &st)) { - DEBUG("failed to stat %s: %s\n", name, strerror(errno)); - return UPDATE_RETURN_ERROR; - } - - if (S_ISREG(st.st_mode) && - hasMusicSuffix(name, 0) && isMusic(name, NULL, 0)) { - struct song *song; - const char *shortname = mpd_basename(name); - - if (!(song = song_file_load(shortname, directory))) - return -1; - songvec_add(&directory->songs, song); - LOG("added %s\n", name); - return UPDATE_RETURN_UPDATED; - } else if (S_ISDIR(st.st_mode)) { - return addSubDirectoryToDirectory(directory, name, &st); - } - - DEBUG("addToDirectory: %s is not a directory or music\n", name); - - return UPDATE_RETURN_ERROR; -} - -static enum update_return updateInDirectory(struct directory *directory, const char *name) { struct song *song; @@ -228,7 +199,12 @@ updateInDirectory(struct directory *directory, const char *name) const char *shortname = mpd_basename(name); if (!(song = songvec_find(&directory->songs, shortname))) { - addToDirectory(directory, name); + song = song_file_load(shortname, directory); + if (song == NULL) + return -1; + + songvec_add(&directory->songs, song); + LOG("added %s\n", name); return UPDATE_RETURN_UPDATED; } else if (st.st_mtime != song->mtime) { LOG("updating %s\n", name); @@ -247,6 +223,8 @@ updateInDirectory(struct directory *directory, const char *name) } } + DEBUG("update: %s is not a directory or music\n", name); + return UPDATE_RETURN_NOUPDATE; } @@ -293,14 +271,9 @@ updateDirectory(struct directory *directory) if (!isRootDirectory(directory->path)) utf8 = pfx_dir(path_max_tmp, utf8, strlen(utf8), dirname, strlen(dirname)); - 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; - } + if (updateInDirectory(directory, path_max_tmp) == + UPDATE_RETURN_UPDATED) + ret = UPDATE_RETURN_UPDATED; } closedir(dir); @@ -446,7 +419,7 @@ static enum update_return updatePath(const char *utf8path) } else if (0 == inodeFoundInParent(parentDirectory->parent, parentDirectory->inode, parentDirectory->device) - && addToDirectory(parentDirectory, path) + && updateInDirectory(parentDirectory, path) == UPDATE_RETURN_UPDATED) { ret = UPDATE_RETURN_UPDATED; } |