aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-10-04 03:41:59 -0700
committerEric Wong <normalperson@yhbt.net>2008-10-04 03:41:59 -0700
commitb84bf082df6ec5a7223c86abb94d799569aed1c1 (patch)
tree43c12a72382b43be31fcdeb8ff9bea6acf6f1fb4 /src
parente46bbc95eae9bc75e6d809cdf157637b682765c2 (diff)
downloadmpd-b84bf082df6ec5a7223c86abb94d799569aed1c1.tar.gz
mpd-b84bf082df6ec5a7223c86abb94d799569aed1c1.tar.xz
mpd-b84bf082df6ec5a7223c86abb94d799569aed1c1.zip
directory: reuse existing directory if found on update
Instead of allocating a new one, just reuse an existing one if one is found when rereading the DB. This is a small makes the previous commit work on subdirectories of the root music directory. [1] "song: better handling of existing songs when rereading DB"
Diffstat (limited to '')
-rw-r--r--src/directory.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/directory.c b/src/directory.c
index fc9c6b41d..fb0ca0b07 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -723,12 +723,13 @@ static void readDirectoryInfo(FILE * fp, Directory * directory)
char buffer[MPD_PATH_MAX * 2];
int bufferSize = MPD_PATH_MAX * 2;
char key[MPD_PATH_MAX * 2];
- Directory *subDirectory;
char *name;
while (myFgets(buffer, bufferSize, fp)
&& prefixcmp(buffer, DIRECTORY_END)) {
if (!prefixcmp(buffer, DIRECTORY_DIR)) {
+ Directory *subdir;
+
strcpy(key, &(buffer[strlen(DIRECTORY_DIR)]));
if (!myFgets(buffer, bufferSize, fp))
FATAL("Error reading db, fgets\n");
@@ -740,9 +741,13 @@ static void readDirectoryInfo(FILE * fp, Directory * directory)
if (prefixcmp(buffer, DIRECTORY_BEGIN))
FATAL("Error reading db at line: %s\n", buffer);
name = &(buffer[strlen(DIRECTORY_BEGIN)]);
- subDirectory = newDirectory(name, directory);
- dirvec_add(&directory->children, subDirectory);
- readDirectoryInfo(fp, subDirectory);
+ if ((subdir = getDirectory(name))) {
+ assert(subdir->parent == directory);
+ } else {
+ subdir = newDirectory(name, directory);
+ dirvec_add(&directory->children, subdir);
+ }
+ readDirectoryInfo(fp, subdir);
} else if (!prefixcmp(buffer, SONG_BEGIN)) {
readSongInfoIntoList(fp, directory);
} else {