diff options
author | Max Kellermann <max@duempel.org> | 2014-02-26 08:39:44 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-02-27 20:49:13 +0100 |
commit | e9a85aa4e4d0634548b5c97461beb27ae5559338 (patch) | |
tree | 7cdfdd0ae0d990a8adbecc34f32d073627483205 /src/db/plugins/simple/Directory.cxx | |
parent | 2a16fc74fd354484a70efcc5b6dbfcdd73ee5f5a (diff) | |
download | mpd-e9a85aa4e4d0634548b5c97461beb27ae5559338.tar.gz mpd-e9a85aa4e4d0634548b5c97461beb27ae5559338.tar.xz mpd-e9a85aa4e4d0634548b5c97461beb27ae5559338.zip |
db/simple: mount points
A SimpleDatabase instance can now "mount" other Database instances at
certain locations. This is used to use a new SimpleDatabase instance
for each storage mount (issued with the "mount" protocol command).
Each such instance has its own database file, stored in the directory
that is specified with the "cache_directory" option.
Diffstat (limited to '')
-rw-r--r-- | src/db/plugins/simple/Directory.cxx | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/db/plugins/simple/Directory.cxx b/src/db/plugins/simple/Directory.cxx index b4255b0ac..3ac2f96a2 100644 --- a/src/db/plugins/simple/Directory.cxx +++ b/src/db/plugins/simple/Directory.cxx @@ -21,10 +21,12 @@ #include "Directory.hxx" #include "SongSort.hxx" #include "Song.hxx" +#include "Mount.hxx" #include "db/LightDirectory.hxx" #include "db/LightSong.hxx" #include "db/Uri.hxx" #include "db/DatabaseLock.hxx" +#include "db/Interface.hxx" #include "SongFilter.hxx" #include "lib/icu/Collate.hxx" #include "fs/Traits.hxx" @@ -42,7 +44,8 @@ extern "C" { Directory::Directory(std::string &&_path_utf8, Directory *_parent) :parent(_parent), mtime(0), have_stat(false), - path(std::move(_path_utf8)) + path(std::move(_path_utf8)), + mounted_database(nullptr) { INIT_LIST_HEAD(&children); INIT_LIST_HEAD(&songs); @@ -50,6 +53,8 @@ Directory::Directory(std::string &&_path_utf8, Directory *_parent) Directory::~Directory() { + delete mounted_database; + Song *song, *ns; directory_for_each_song_safe(song, ns, *this) song->Free(); @@ -113,6 +118,11 @@ Directory::PruneEmpty() Directory *child, *n; directory_for_each_child_safe(child, n, *this) { + if (child->IsMount()) + /* never prune mount points; they're always + empty by definition, but that's ok */ + continue; + child->PruneEmpty(); if (child->IsEmpty()) @@ -233,6 +243,22 @@ Directory::Walk(bool recursive, const SongFilter *filter, { assert(!error.IsDefined()); + if (IsMount()) { + assert(IsEmpty()); + + /* TODO: eliminate this unlock/lock; it is necessary + because the child's SimpleDatabasePlugin::Visit() + call will lock it again */ + db_unlock(); + bool result = WalkMount(GetPath(), *mounted_database, + recursive, filter, + visit_directory, visit_song, + visit_playlist, + error); + db_lock(); + return result; + } + if (visit_song) { Song *song; directory_for_each_song(song, *this) { |