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.
This commit is contained in:
Max Kellermann 2009-11-01 15:34:14 +01:00
parent 10b7608926
commit 451f932d80
1 changed files with 13 additions and 12 deletions

View File

@ -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);