update: pass base file name to updateInDirectory()
In order to optimize buffer usage, pass only the base file name to updateInDirectory(). This way, updateInDirectory() may choose when to allocate a larger buffer for the full path.
This commit is contained in:
parent
270a6ebd69
commit
a52343732b
33
src/update.c
33
src/update.c
@ -241,8 +241,18 @@ make_subdir(struct directory *parent, const char *name)
|
|||||||
struct directory *directory;
|
struct directory *directory;
|
||||||
|
|
||||||
directory = directory_get_child(parent, name);
|
directory = directory_get_child(parent, name);
|
||||||
if (directory == NULL)
|
if (directory == NULL) {
|
||||||
directory = directory_new_child(parent, name);
|
char path[MPD_PATH_MAX];
|
||||||
|
|
||||||
|
if (isRootDirectory(directory_get_path(parent)))
|
||||||
|
strcpy(path, name);
|
||||||
|
else
|
||||||
|
pfx_dir(path, name, strlen(name),
|
||||||
|
directory_get_path(parent),
|
||||||
|
strlen(directory_get_path(parent)));
|
||||||
|
|
||||||
|
directory = directory_new_child(parent, path);
|
||||||
|
}
|
||||||
|
|
||||||
return directory;
|
return directory;
|
||||||
}
|
}
|
||||||
@ -254,20 +264,23 @@ static void
|
|||||||
updateInDirectory(struct directory *directory,
|
updateInDirectory(struct directory *directory,
|
||||||
const char *name, const struct stat *st)
|
const char *name, const struct stat *st)
|
||||||
{
|
{
|
||||||
|
assert(strchr(name, '/') == NULL);
|
||||||
|
|
||||||
if (S_ISREG(st->st_mode) && hasMusicSuffix(name, 0)) {
|
if (S_ISREG(st->st_mode) && hasMusicSuffix(name, 0)) {
|
||||||
const char *shortname = mpd_basename(name);
|
struct song *song = songvec_find(&directory->songs, name);
|
||||||
struct song *song = songvec_find(&directory->songs, shortname);
|
|
||||||
|
|
||||||
if (song == NULL) {
|
if (song == NULL) {
|
||||||
song = song_file_load(shortname, directory);
|
song = song_file_load(name, directory);
|
||||||
if (song == NULL)
|
if (song == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
songvec_add(&directory->songs, song);
|
songvec_add(&directory->songs, song);
|
||||||
modified = true;
|
modified = true;
|
||||||
LOG("added %s\n", name);
|
LOG("added %s/%s\n",
|
||||||
|
directory_get_path(directory), name);
|
||||||
} else if (st->st_mtime != song->mtime) {
|
} else if (st->st_mtime != song->mtime) {
|
||||||
LOG("updating %s\n", name);
|
LOG("updating %s/%s\n",
|
||||||
|
directory_get_path(directory), name);
|
||||||
if (!song_file_update(song))
|
if (!song_file_update(song))
|
||||||
delete_song(directory, song);
|
delete_song(directory, song);
|
||||||
modified = true;
|
modified = true;
|
||||||
@ -330,7 +343,8 @@ updateDirectory(struct directory *directory, const struct stat *st)
|
|||||||
dirname, strlen(dirname));
|
dirname, strlen(dirname));
|
||||||
|
|
||||||
if (myStat(path_max_tmp, &st2) == 0)
|
if (myStat(path_max_tmp, &st2) == 0)
|
||||||
updateInDirectory(directory, path_max_tmp, &st2);
|
updateInDirectory(directory,
|
||||||
|
mpd_basename(path_max_tmp), &st2);
|
||||||
else
|
else
|
||||||
delete_name_in(directory, mpd_basename(path_max_tmp));
|
delete_name_in(directory, mpd_basename(path_max_tmp));
|
||||||
}
|
}
|
||||||
@ -394,7 +408,8 @@ updatePath(const char *path)
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if (myStat(path, &st) == 0)
|
if (myStat(path, &st) == 0)
|
||||||
updateInDirectory(addParentPathToDB(path), path, &st);
|
updateInDirectory(addParentPathToDB(path),
|
||||||
|
mpd_basename(path), &st);
|
||||||
else
|
else
|
||||||
delete_path(path);
|
delete_path(path);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user