diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-10-12 05:28:25 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-10-12 05:29:27 -0700 |
commit | 7278e3b2ee49a853b01dc6532bd7067a264f235d (patch) | |
tree | 28e83de310f0c58df226e253a82b0d43ff784497 /src/database.c | |
parent | c87ce02575e0a9d5ac3e50938688187ea28ad400 (diff) | |
parent | c7579ca2d8422f0172537e1ca7d1bd46edfc4f9d (diff) | |
download | mpd-7278e3b2ee49a853b01dc6532bd7067a264f235d.tar.gz mpd-7278e3b2ee49a853b01dc6532bd7067a264f235d.tar.xz mpd-7278e3b2ee49a853b01dc6532bd7067a264f235d.zip |
Merge branch 'ew/directory'
* ew/directory: (21 commits)
update: fix multiple deletes from *vec iterators
directory: children leave parents before being free()ed
directory: always maintain sorted properties vectors
update: simplify the serialized_delete usage a bit
update: remove delete_each_song and clear_directory
directory: directory_free kills all that it contains
update: serialize directory deletions
update: serialize song_free in main thread
dirvec: introduce locking for all iterators
dirvec: use dirvec_for_each where it makes sense
dirvec: add dirvec_for_each iterator
songvec: avoid holding nr_lock during free(3)
update: allow music_root updates to be queued
update: validate in command.c and fix small memory leak
directory: rename isRootDirectory => path_is_music_root
Avoid calling isRootDirectory when we have a directory object
directory: make music_root global and avoid runtime initialization
directory: use mpd_sizeof_str_flex_array for path, too
tag_item: avoid wasting space when struct is unpackable
song: use mpd_sizeof_str_flex_array for song.url
...
[ew: fixed up merge errors with myself when isRootDirectory
went away]
Diffstat (limited to 'src/database.c')
-rw-r--r-- | src/database.c | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/src/database.c b/src/database.c index dde57ce6a..733180fea 100644 --- a/src/database.c +++ b/src/database.c @@ -32,14 +32,10 @@ #include "os_compat.h" #include "myfprintf.h" -static struct directory *music_root; - static time_t directory_dbModTime; void db_init(void) { - music_root = directory_new("", NULL); - if (!directory_update_init(NULL)) FATAL("directory update failed\n"); @@ -54,22 +50,12 @@ void db_init(void) void db_finish(void) { - directory_free(music_root); -} - -struct directory * db_get_root(void) -{ - assert(music_root != NULL); - - return music_root; + directory_free(&music_root); } struct directory * db_get_directory(const char *name) { - if (name == NULL) - return music_root; - - return directory_get_subdir(music_root, name); + return name ? directory_get_subdir(&music_root, name) : &music_root; } struct mpd_song *db_get_song(const char *file) @@ -195,11 +181,7 @@ int db_save(void) struct stat st; DEBUG("removing empty directories from DB\n"); - directory_prune_empty(music_root); - - DEBUG("sorting DB\n"); - - directory_sort(music_root); + directory_prune_empty(&music_root); DEBUG("writing DB\n"); @@ -220,7 +202,7 @@ int db_save(void) DIRECTORY_FS_CHARSET "%s\n" DIRECTORY_INFO_END "\n", getFsCharset()); - if (directory_save(fd, music_root) < 0) { + if (directory_save(fd, &music_root) < 0) { ERROR("Failed to write to database file: %s\n", strerror(errno)); xclose(fd); @@ -243,8 +225,6 @@ int db_load(void) int foundFsCharset = 0; int foundVersion = 0; - if (!music_root) - music_root = directory_new("", NULL); while (!(fp = fopen(dbFile, "r")) && errno == EINTR) ; if (fp == NULL) { ERROR("unable to open db file \"%s\": %s\n", @@ -296,7 +276,7 @@ int db_load(void) DEBUG("reading DB\n"); - directory_load(fp, music_root); + directory_load(fp, &music_root); while (fclose(fp) && errno == EINTR) ; stats.numberOfSongs = countSongsIn(NULL); |