summaryrefslogtreecommitdiff
path: root/src/command/OtherCommands.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-02-28 19:02:23 +0100
committerMax Kellermann <max@duempel.org>2014-03-01 06:25:57 +0100
commit96afa8bd2ba44d6669949db5fce4fee5f826b753 (patch)
treea484d32c412b2cb716cc149a42f702e8c3013f48 /src/command/OtherCommands.cxx
parent797bbeabeb212ee3d818acdb19d85e2d8642f5ed (diff)
command: add command "listfiles"
Lists files and directories. Supports storage plugins.
Diffstat (limited to 'src/command/OtherCommands.cxx')
-rw-r--r--src/command/OtherCommands.cxx37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/command/OtherCommands.cxx b/src/command/OtherCommands.cxx
index 6415e84df..eac26735b 100644
--- a/src/command/OtherCommands.cxx
+++ b/src/command/OtherCommands.cxx
@@ -19,6 +19,8 @@
#include "config.h"
#include "OtherCommands.hxx"
+#include "FileCommands.hxx"
+#include "StorageCommands.hxx"
#include "CommandError.hxx"
#include "db/Uri.hxx"
#include "storage/StorageInterface.hxx"
@@ -112,6 +114,41 @@ print_tag(TagType type, const char *value, void *ctx)
tag_print(client, type, value);
}
+CommandResult
+handle_listfiles(Client &client, int argc, char *argv[])
+{
+ const char *const uri = argc == 2
+ ? argv[1]
+ /* default is root directory */
+ : "";
+
+ if (memcmp(uri, "file:///", 8) == 0)
+ /* list local directory */
+ return handle_listfiles_local(client, uri + 7);
+
+#ifdef ENABLE_DATABASE
+ if (uri_has_scheme(uri))
+ /* use storage plugin to list remote directory */
+ return handle_listfiles_storage(client, uri);
+
+ /* must be a path relative to the configured
+ music_directory */
+
+ if (client.partition.instance.storage != nullptr)
+ /* if we have a storage instance, obtain a list of
+ files from it */
+ return handle_listfiles_storage(client,
+ *client.partition.instance.storage,
+ uri);
+
+ /* fall back to entries from database if we have no storage */
+ return handle_listfiles_db(client, uri);
+#else
+ command_error(client, ACK_ERROR_NO_EXIST, "No database");
+ return CommandResult::ERROR;
+#endif
+}
+
static constexpr tag_handler print_tag_handler = {
nullptr,
print_tag,