directory_save: abort on duplicate subdirectory

The old code tried to recover, but what's the point of that?  If a
directory is duplicate, something is wrong with the database file.
This commit is contained in:
Max Kellermann 2009-11-01 15:34:13 +01:00
parent 22279127f9
commit 2cd8a9fecf

View File

@ -86,6 +86,12 @@ directory_load_subdir(FILE *fp, struct directory *parent, const char *name,
struct directory *directory; struct directory *directory;
bool success; bool success;
if (directory_get_child(parent, name) != NULL) {
g_set_error(error_r, directory_quark(), 0,
"Duplicate subdirectory '%s'", name);
return NULL;
}
if (!fgets(buffer, sizeof(buffer), fp)) { if (!fgets(buffer, sizeof(buffer), fp)) {
g_set_error(error_r, directory_quark(), 0, g_set_error(error_r, directory_quark(), 0,
"Unexpected end of file"); "Unexpected end of file");
@ -119,13 +125,7 @@ directory_load_subdir(FILE *fp, struct directory *parent, const char *name,
return NULL; return NULL;
} }
directory = directory_get_child(parent, name); directory = directory_new(name, parent);
if (directory != NULL) {
assert(directory->parent == parent);
} else {
directory = directory_new(name, parent);
dirvec_add(&parent->children, directory);
}
success = directory_load(fp, directory, error_r); success = directory_load(fp, directory, error_r);
if (!success) if (!success)
@ -151,6 +151,8 @@ directory_load(FILE *fp, struct directory *directory, GError **error)
error); error);
if (subdir == NULL) if (subdir == NULL)
return false; return false;
dirvec_add(&directory->children, subdir);
} else if (g_str_has_prefix(buffer, SONG_BEGIN)) { } else if (g_str_has_prefix(buffer, SONG_BEGIN)) {
success = songvec_load(fp, &directory->songs, success = songvec_load(fp, &directory->songs,
directory, error); directory, error);