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"
This commit is contained in:
parent
fb4d55c5b3
commit
836dcc28c5
@ -740,12 +740,13 @@ static void readDirectoryInfo(FILE * fp, Directory * directory)
|
|||||||
char buffer[MPD_PATH_MAX * 2];
|
char buffer[MPD_PATH_MAX * 2];
|
||||||
int bufferSize = MPD_PATH_MAX * 2;
|
int bufferSize = MPD_PATH_MAX * 2;
|
||||||
char key[MPD_PATH_MAX * 2];
|
char key[MPD_PATH_MAX * 2];
|
||||||
Directory *subDirectory;
|
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
while (myFgets(buffer, bufferSize, fp)
|
while (myFgets(buffer, bufferSize, fp)
|
||||||
&& prefixcmp(buffer, DIRECTORY_END)) {
|
&& prefixcmp(buffer, DIRECTORY_END)) {
|
||||||
if (!prefixcmp(buffer, DIRECTORY_DIR)) {
|
if (!prefixcmp(buffer, DIRECTORY_DIR)) {
|
||||||
|
Directory *subdir;
|
||||||
|
|
||||||
strcpy(key, &(buffer[strlen(DIRECTORY_DIR)]));
|
strcpy(key, &(buffer[strlen(DIRECTORY_DIR)]));
|
||||||
if (!myFgets(buffer, bufferSize, fp))
|
if (!myFgets(buffer, bufferSize, fp))
|
||||||
FATAL("Error reading db, fgets\n");
|
FATAL("Error reading db, fgets\n");
|
||||||
@ -757,9 +758,13 @@ static void readDirectoryInfo(FILE * fp, Directory * directory)
|
|||||||
if (prefixcmp(buffer, DIRECTORY_BEGIN))
|
if (prefixcmp(buffer, DIRECTORY_BEGIN))
|
||||||
FATAL("Error reading db at line: %s\n", buffer);
|
FATAL("Error reading db at line: %s\n", buffer);
|
||||||
name = &(buffer[strlen(DIRECTORY_BEGIN)]);
|
name = &(buffer[strlen(DIRECTORY_BEGIN)]);
|
||||||
subDirectory = newDirectory(name, directory);
|
if ((subdir = getDirectory(name))) {
|
||||||
dirvec_add(&directory->children, subDirectory);
|
assert(subdir->parent == directory);
|
||||||
readDirectoryInfo(fp, subDirectory);
|
} else {
|
||||||
|
subdir = newDirectory(name, directory);
|
||||||
|
dirvec_add(&directory->children, subdir);
|
||||||
|
}
|
||||||
|
readDirectoryInfo(fp, subdir);
|
||||||
} else if (!prefixcmp(buffer, SONG_BEGIN)) {
|
} else if (!prefixcmp(buffer, SONG_BEGIN)) {
|
||||||
readSongInfoIntoList(fp, &directory->songs, directory);
|
readSongInfoIntoList(fp, &directory->songs, directory);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user