update: removed addToDirectory()
Use updateInDirectory() instead of addToDirectory(). Eliminate a duplicate stat() in updateInDirectory() by calling song_file_update() directly.
This commit is contained in:
parent
60d122e850
commit
476578d2a9
51
src/update.c
51
src/update.c
@ -186,35 +186,6 @@ addSubDirectoryToDirectory(struct directory *directory,
|
|||||||
return UPDATE_RETURN_UPDATED;
|
return UPDATE_RETURN_UPDATED;
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
static enum update_return
|
||||||
updateInDirectory(struct directory *directory, const char *name)
|
updateInDirectory(struct directory *directory, const char *name)
|
||||||
{
|
{
|
||||||
@ -228,7 +199,12 @@ updateInDirectory(struct directory *directory, const char *name)
|
|||||||
const char *shortname = mpd_basename(name);
|
const char *shortname = mpd_basename(name);
|
||||||
|
|
||||||
if (!(song = songvec_find(&directory->songs, shortname))) {
|
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;
|
return UPDATE_RETURN_UPDATED;
|
||||||
} else if (st.st_mtime != song->mtime) {
|
} else if (st.st_mtime != song->mtime) {
|
||||||
LOG("updating %s\n", name);
|
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;
|
return UPDATE_RETURN_NOUPDATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,14 +271,9 @@ updateDirectory(struct directory *directory)
|
|||||||
if (!isRootDirectory(directory->path))
|
if (!isRootDirectory(directory->path))
|
||||||
utf8 = pfx_dir(path_max_tmp, utf8, strlen(utf8),
|
utf8 = pfx_dir(path_max_tmp, utf8, strlen(utf8),
|
||||||
dirname, strlen(dirname));
|
dirname, strlen(dirname));
|
||||||
if (was_empty) {
|
if (updateInDirectory(directory, path_max_tmp) ==
|
||||||
if (addToDirectory(directory, path_max_tmp) ==
|
UPDATE_RETURN_UPDATED)
|
||||||
UPDATE_RETURN_UPDATED)
|
ret = UPDATE_RETURN_UPDATED;
|
||||||
ret = UPDATE_RETURN_UPDATED;
|
|
||||||
} else {
|
|
||||||
if (updateInDirectory(directory, path_max_tmp) > 0)
|
|
||||||
ret = UPDATE_RETURN_UPDATED;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
@ -446,7 +419,7 @@ static enum update_return updatePath(const char *utf8path)
|
|||||||
} else if (0 == inodeFoundInParent(parentDirectory->parent,
|
} else if (0 == inodeFoundInParent(parentDirectory->parent,
|
||||||
parentDirectory->inode,
|
parentDirectory->inode,
|
||||||
parentDirectory->device)
|
parentDirectory->device)
|
||||||
&& addToDirectory(parentDirectory, path)
|
&& updateInDirectory(parentDirectory, path)
|
||||||
== UPDATE_RETURN_UPDATED) {
|
== UPDATE_RETURN_UPDATED) {
|
||||||
ret = UPDATE_RETURN_UPDATED;
|
ret = UPDATE_RETURN_UPDATED;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user