diff options
author | Max Kellermann <max@duempel.org> | 2009-11-01 17:51:29 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-11-01 17:51:29 +0100 |
commit | 4b17aca7476dacfbd3b3220ff8013724f5eed0c9 (patch) | |
tree | 42af2d45d3345026a4eb929e792eca384b5c34c3 /src/directory_save.c | |
parent | 63dda94a027d324fa3d0c9404a440e3f5e15cede (diff) | |
download | mpd-4b17aca7476dacfbd3b3220ff8013724f5eed0c9.tar.gz mpd-4b17aca7476dacfbd3b3220ff8013724f5eed0c9.tar.xz mpd-4b17aca7476dacfbd3b3220ff8013724f5eed0c9.zip |
song_save: load one song at a time
Changed songvec_load() to song_load(). Added start and end markers
for each song. Removed the "key" line, it's redundant.
Diffstat (limited to 'src/directory_save.c')
-rw-r--r-- | src/directory_save.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/directory_save.c b/src/directory_save.c index e6d3649d0..a22d28ffb 100644 --- a/src/directory_save.c +++ b/src/directory_save.c @@ -144,7 +144,6 @@ directory_load(FILE *fp, struct directory *directory, GString *buffer, GError **error) { const char *line; - bool success; while ((line = read_text_line(fp, buffer)) != NULL && !g_str_has_prefix(line, DIRECTORY_END)) { @@ -157,11 +156,22 @@ directory_load(FILE *fp, struct directory *directory, return false; dirvec_add(&directory->children, subdir); - } else if (strcmp(line, SONG_BEGIN) == 0) { - success = songvec_load(fp, &directory->songs, - directory, buffer, error); - if (!success) + } else if (g_str_has_prefix(line, SONG_BEGIN)) { + const char *name = line + sizeof(SONG_BEGIN) - 1; + struct song *song; + + if (songvec_find(&directory->songs, name) != NULL) { + g_set_error(error, directory_quark(), 0, + "Duplicate song '%s'", name); + return NULL; + } + + song = song_load(fp, directory, name, + buffer, error); + if (song == NULL) return false; + + songvec_add(&directory->songs, song); } else { g_set_error(error, directory_quark(), 0, "Malformed line: %s", line); |