From 451f932d80f5b695adb59e293391d17c9b996fb8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 1 Nov 2009 15:34:14 +0100 Subject: [PATCH] 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. --- src/directory_save.c | 25 +++++++++++++------------ 1 file 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);