diff options
author | Max Kellermann <max@duempel.org> | 2014-02-12 21:46:32 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-02-12 21:47:59 +0100 |
commit | 0935ae330abe4aca1b63d46eaaa2f8a67c06375f (patch) | |
tree | f17056f744f74a37ba5f588d7fd1a803ad984879 /src/storage | |
parent | 9e02b13ab3b26ca1da6b1df2cf6ad9e9b281b2e0 (diff) | |
download | mpd-0935ae330abe4aca1b63d46eaaa2f8a67c06375f.tar.gz mpd-0935ae330abe4aca1b63d46eaaa2f8a67c06375f.tar.xz mpd-0935ae330abe4aca1b63d46eaaa2f8a67c06375f.zip |
StorageCommands: add command "listmounts"
Diffstat (limited to 'src/storage')
-rw-r--r-- | src/storage/CompositeStorage.hxx | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/storage/CompositeStorage.hxx b/src/storage/CompositeStorage.hxx index 696ffff61..9c10f76f4 100644 --- a/src/storage/CompositeStorage.hxx +++ b/src/storage/CompositeStorage.hxx @@ -95,6 +95,18 @@ public: CompositeStorage(); virtual ~CompositeStorage(); + /** + * Call the given function for each mounted storage, including + * the root storage. Passes mount point URI and the a const + * Storage reference to the function. + */ + template<typename T> + void VisitMounts(T t) const { + const ScopeLock protect(mutex); + std::string uri; + VisitMounts(uri, root, t); + } + void Mount(const char *uri, Storage *storage); bool Unmount(const char *uri); @@ -112,6 +124,26 @@ public: virtual const char *MapToRelativeUTF8(const char *uri) const override; private: + template<typename T> + void VisitMounts(std::string &uri, const Directory &directory, + T t) const { + const Storage *const storage = directory.storage; + if (storage != nullptr) + t(uri.c_str(), *storage); + + if (!uri.empty()) + uri.push_back('/'); + + const size_t uri_length = uri.length(); + + for (const auto &i : directory.children) { + uri.resize(uri_length); + uri.append(i.first); + + VisitMounts(uri, i.second, t); + } + } + gcc_pure FindResult FindStorage(const char *uri) const; FindResult FindStorage(const char *uri, Error &error) const; |