aboutsummaryrefslogtreecommitdiffstats
path: root/src/directory_save.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-11-01 15:34:14 +0100
committerMax Kellermann <max@duempel.org>2009-11-01 15:34:14 +0100
commit451f932d80f5b695adb59e293391d17c9b996fb8 (patch)
treec62076dc7ce798c77fa3dc0cabb9aeb11943117e /src/directory_save.c
parent10b760892602d8ddb7c413d5f91f990daf8a4dca (diff)
downloadmpd-451f932d80f5b695adb59e293391d17c9b996fb8.tar.gz
mpd-451f932d80f5b695adb59e293391d17c9b996fb8.tar.xz
mpd-451f932d80f5b695adb59e293391d17c9b996fb8.zip
directory_save: allocate directory object earlier, assign mtime
Allocate the directory object after the "directory:" line. Assign the mtime from the input file to this new object, instead of to the parent directory.
Diffstat (limited to '')
-rw-r--r--src/directory_save.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/directory_save.c b/src/directory_save.c
index d301d168b..f353c7c2e 100644
--- a/src/directory_save.c
+++ b/src/directory_save.c
@@ -92,20 +92,31 @@ directory_load_subdir(FILE *fp, struct directory *parent, const char *name,
return NULL;
}
+ if (directory_is_root(parent)) {
+ directory = directory_new(name, parent);
+ } else {
+ char *path = g_strconcat(directory_get_path(parent), "/",
+ name, NULL);
+ directory = directory_new(path, parent);
+ g_free(path);
+ }
+
if (!fgets(buffer, sizeof(buffer), fp)) {
g_set_error(error_r, directory_quark(), 0,
"Unexpected end of file");
+ directory_free(directory);
return NULL;
}
if (g_str_has_prefix(buffer, DIRECTORY_MTIME)) {
- parent->mtime =
+ directory->mtime =
g_ascii_strtoull(buffer + sizeof(DIRECTORY_MTIME) - 1,
NULL, 10);
if (!fgets(buffer, sizeof(buffer), fp)) {
g_set_error(error_r, directory_quark(), 0,
"Unexpected end of file");
+ directory_free(directory);
return NULL;
}
}
@@ -113,20 +124,10 @@ directory_load_subdir(FILE *fp, struct directory *parent, const char *name,
if (!g_str_has_prefix(buffer, DIRECTORY_BEGIN)) {
g_set_error(error_r, directory_quark(), 0,
"Malformed line: %s", buffer);
+ directory_free(directory);
return NULL;
}
- g_strchomp(buffer);
- name = &(buffer[strlen(DIRECTORY_BEGIN)]);
- if (!g_str_has_prefix(name, parent->path) != 0) {
- g_set_error(error_r, directory_quark(), 0,
- "Wrong path in database: '%s' in '%s'",
- name, parent->path);
- return NULL;
- }
-
- directory = directory_new(name, parent);
-
success = directory_load(fp, directory, error_r);
if (!success) {
directory_free(directory);