diff options
Diffstat (limited to 'src/directory_save.c')
-rw-r--r-- | src/directory_save.c | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/src/directory_save.c b/src/directory_save.c index 55896c289..de1df050a 100644 --- a/src/directory_save.c +++ b/src/directory_save.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2010 The Music Player Daemon Project + * Copyright (C) 2003-2011 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -28,6 +28,7 @@ #include <assert.h> #include <string.h> +#define DIRECTORY_DIR "directory: " #define DIRECTORY_MTIME "mtime: " #define DIRECTORY_BEGIN "begin: " #define DIRECTORY_END "end: " @@ -42,11 +43,8 @@ directory_quark(void) } void -directory_save(FILE *fp, struct directory *directory) +directory_save(FILE *fp, const struct directory *directory) { - struct dirvec *children = &directory->children; - size_t i; - if (!directory_is_root(directory)) { fprintf(fp, DIRECTORY_MTIME "%lu\n", (unsigned long)directory->mtime); @@ -55,8 +53,8 @@ directory_save(FILE *fp, struct directory *directory) directory_get_path(directory)); } - for (i = 0; i < children->nr; ++i) { - struct directory *cur = children->base[i]; + struct directory *cur; + directory_for_each_child(cur, directory) { char *base = g_path_get_basename(cur->path); fprintf(fp, DIRECTORY_DIR "%s\n", base); @@ -68,7 +66,9 @@ directory_save(FILE *fp, struct directory *directory) return; } - songvec_save(fp, &directory->songs); + struct song *song; + directory_for_each_song(song, directory) + song_save(fp, song); playlist_vector_save(fp, &directory->playlists); @@ -81,7 +81,6 @@ static struct directory * directory_load_subdir(FILE *fp, struct directory *parent, const char *name, GString *buffer, GError **error_r) { - struct directory *directory; const char *line; bool success; @@ -91,20 +90,13 @@ 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); - } + struct directory *directory = directory_new_child(parent, name); line = read_text_line(fp, buffer); if (line == NULL) { g_set_error(error_r, directory_quark(), 0, "Unexpected end of file"); - directory_free(directory); + directory_delete(directory); return NULL; } @@ -117,7 +109,7 @@ directory_load_subdir(FILE *fp, struct directory *parent, const char *name, if (line == NULL) { g_set_error(error_r, directory_quark(), 0, "Unexpected end of file"); - directory_free(directory); + directory_delete(directory); return NULL; } } @@ -125,13 +117,13 @@ directory_load_subdir(FILE *fp, struct directory *parent, const char *name, if (!g_str_has_prefix(line, DIRECTORY_BEGIN)) { g_set_error(error_r, directory_quark(), 0, "Malformed line: %s", line); - directory_free(directory); + directory_delete(directory); return NULL; } success = directory_load(fp, directory, buffer, error_r); if (!success) { - directory_free(directory); + directory_delete(directory); return NULL; } @@ -153,13 +145,11 @@ directory_load(FILE *fp, struct directory *directory, buffer, error); if (subdir == NULL) return false; - - dirvec_add(&directory->children, subdir); } 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) { + if (directory_get_song(directory, name) != NULL) { g_set_error(error, directory_quark(), 0, "Duplicate song '%s'", name); return NULL; @@ -170,7 +160,7 @@ directory_load(FILE *fp, struct directory *directory, if (song == NULL) return false; - songvec_add(&directory->songs, song); + directory_add_song(directory, song); } else if (g_str_has_prefix(line, PLAYLIST_META_BEGIN)) { /* duplicate the name, because playlist_metadata_load() will overwrite the |