From 96afa8bd2ba44d6669949db5fce4fee5f826b753 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 28 Feb 2014 19:02:23 +0100 Subject: command: add command "listfiles" Lists files and directories. Supports storage plugins. --- src/command/OtherCommands.cxx | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/command/OtherCommands.cxx') 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, -- cgit v1.2.3