From a52343732b31849e1540e1c97f0d8e5c1b300828 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 13 Oct 2008 16:55:54 +0200 Subject: 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. --- src/update.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/update.c b/src/update.c index 1ed673f64..0219dad56 100644 --- a/src/update.c +++ b/src/update.c @@ -241,8 +241,18 @@ make_subdir(struct directory *parent, const char *name) struct directory *directory; directory = directory_get_child(parent, name); - if (directory == NULL) - directory = directory_new_child(parent, name); + if (directory == NULL) { + 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; } @@ -254,20 +264,23 @@ static void updateInDirectory(struct directory *directory, const char *name, const struct stat *st) { + assert(strchr(name, '/') == NULL); + if (S_ISREG(st->st_mode) && hasMusicSuffix(name, 0)) { - const char *shortname = mpd_basename(name); - struct song *song = songvec_find(&directory->songs, shortname); + struct song *song = songvec_find(&directory->songs, name); if (song == NULL) { - song = song_file_load(shortname, directory); + song = song_file_load(name, directory); if (song == NULL) return; songvec_add(&directory->songs, song); modified = true; - LOG("added %s\n", name); + LOG("added %s/%s\n", + directory_get_path(directory), name); } 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)) delete_song(directory, song); modified = true; @@ -330,7 +343,8 @@ updateDirectory(struct directory *directory, const struct stat *st) dirname, strlen(dirname)); if (myStat(path_max_tmp, &st2) == 0) - updateInDirectory(directory, path_max_tmp, &st2); + updateInDirectory(directory, + mpd_basename(path_max_tmp), &st2); else delete_name_in(directory, mpd_basename(path_max_tmp)); } @@ -394,7 +408,8 @@ updatePath(const char *path) struct stat st; if (myStat(path, &st) == 0) - updateInDirectory(addParentPathToDB(path), path, &st); + updateInDirectory(addParentPathToDB(path), + mpd_basename(path), &st); else delete_path(path); } -- cgit v1.2.3