diff --git a/src/command/AllCommands.cxx b/src/command/AllCommands.cxx index ca2f29a9a..2828beffa 100644 --- a/src/command/AllCommands.cxx +++ b/src/command/AllCommands.cxx @@ -234,6 +234,12 @@ command_available([[maybe_unused]] const Partition &partition, return neighbor_commands_available(partition.instance); #endif +#ifdef ENABLE_DATABASE + if (StringIsEqual(cmd->cmd, "mount") || + StringIsEqual(cmd->cmd, "unmount")) + return mount_commands_available(partition.instance); +#endif + if (StringIsEqual(cmd->cmd, "save") || StringIsEqual(cmd->cmd, "rm") || StringIsEqual(cmd->cmd, "rename") || diff --git a/src/command/StorageCommands.cxx b/src/command/StorageCommands.cxx index 60c6cefb3..561b25c8b 100644 --- a/src/command/StorageCommands.cxx +++ b/src/command/StorageCommands.cxx @@ -275,3 +275,15 @@ handle_unmount(Client &client, Request args, Response &r) return CommandResult::OK; } + +bool +mount_commands_available(Instance &instance) noexcept +{ +#ifdef ENABLE_DATABASE + if (auto *db = dynamic_cast(instance.GetDatabase())) { + return db->HasCache(); + } +#endif + + return false; +} diff --git a/src/command/StorageCommands.hxx b/src/command/StorageCommands.hxx index 92b4f3c55..b8b36303d 100644 --- a/src/command/StorageCommands.hxx +++ b/src/command/StorageCommands.hxx @@ -22,6 +22,7 @@ #include "CommandResult.hxx" +struct Instance; class Client; class Storage; class Request; @@ -42,4 +43,8 @@ handle_mount(Client &client, Request request, Response &response); CommandResult handle_unmount(Client &client, Request request, Response &response); +[[gnu::pure]] +bool +mount_commands_available(Instance &instance) noexcept; + #endif diff --git a/src/db/plugins/simple/SimpleDatabasePlugin.hxx b/src/db/plugins/simple/SimpleDatabasePlugin.hxx index f35af32f2..a5cefbd88 100644 --- a/src/db/plugins/simple/SimpleDatabasePlugin.hxx +++ b/src/db/plugins/simple/SimpleDatabasePlugin.hxx @@ -86,6 +86,10 @@ public: return *root; } + bool HasCache() const noexcept { + return !cache_path.IsNull(); + } + void Save(); /**