From df9667a4970e13f71571f12dfa2fa4ee5acde319 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@duempel.org>
Date: Wed, 12 Feb 2014 21:45:04 +0100
Subject: [PATCH] StorageCommands: add command "unmount"

---
 src/command/AllCommands.cxx     |  3 +++
 src/command/StorageCommands.cxx | 27 +++++++++++++++++++++++++++
 src/command/StorageCommands.hxx |  3 +++
 3 files changed, 33 insertions(+)

diff --git a/src/command/AllCommands.cxx b/src/command/AllCommands.cxx
index a27bfd79c..488c27daa 100644
--- a/src/command/AllCommands.cxx
+++ b/src/command/AllCommands.cxx
@@ -181,6 +181,9 @@ static const struct command commands[] = {
 	{ "swapid", PERMISSION_CONTROL, 2, 2, handle_swapid },
 	{ "tagtypes", PERMISSION_READ, 0, 0, handle_tagtypes },
 	{ "toggleoutput", PERMISSION_ADMIN, 1, 1, handle_toggleoutput },
+#ifdef ENABLE_DATABASE
+	{ "unmount", PERMISSION_ADMIN, 1, 1, handle_unmount },
+#endif
 	{ "unsubscribe", PERMISSION_READ, 1, 1, handle_unsubscribe },
 	{ "update", PERMISSION_CONTROL, 0, 1, handle_update },
 	{ "urlhandlers", PERMISSION_READ, 0, 0, handle_urlhandlers },
diff --git a/src/command/StorageCommands.cxx b/src/command/StorageCommands.cxx
index a538c77fb..92d235f4c 100644
--- a/src/command/StorageCommands.cxx
+++ b/src/command/StorageCommands.cxx
@@ -113,3 +113,30 @@ handle_mount(Client &client, gcc_unused int argc, char *argv[])
 	idle_add(IDLE_MOUNT);
 	return CommandResult::OK;
 }
+
+CommandResult
+handle_unmount(Client &client, gcc_unused int argc, char *argv[])
+{
+	Storage *_composite = client.partition.instance.storage;
+	if (_composite == nullptr) {
+		command_error(client, ACK_ERROR_NO_EXIST, "No database");
+		return CommandResult::ERROR;
+	}
+
+	CompositeStorage &composite = *(CompositeStorage *)_composite;
+
+	const char *const local_uri = argv[1];
+
+	if (*local_uri == 0) {
+		command_error(client, ACK_ERROR_ARG, "Bad mount point");
+		return CommandResult::ERROR;
+	}
+
+	if (!composite.Unmount(local_uri)) {
+		command_error(client, ACK_ERROR_ARG, "Not a mount point");
+		return CommandResult::ERROR;
+	}
+
+	idle_add(IDLE_MOUNT);
+	return CommandResult::OK;
+}
diff --git a/src/command/StorageCommands.hxx b/src/command/StorageCommands.hxx
index 33afda34a..82470a0e2 100644
--- a/src/command/StorageCommands.hxx
+++ b/src/command/StorageCommands.hxx
@@ -30,4 +30,7 @@ handle_listmounts(Client &client, int argc, char *argv[]);
 CommandResult
 handle_mount(Client &client, int argc, char *argv[]);
 
+CommandResult
+handle_unmount(Client &client, int argc, char *argv[]);
+
 #endif