diff options
author | Max Kellermann <max@musicpd.org> | 2020-01-20 09:10:02 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2020-01-20 14:56:31 +0100 |
commit | cc7f66822ed4e4f673255f3094bdc123831d8c56 (patch) | |
tree | 41dde0044002890840204898c21db53c364669b7 /src/command | |
parent | 9cbfa66886257d0df4c677c01e37be05bbf6f266 (diff) |
command/partition: add command "delpartition"
Diffstat (limited to 'src/command')
-rw-r--r-- | src/command/AllCommands.cxx | 1 | ||||
-rw-r--r-- | src/command/PartitionCommands.cxx | 42 | ||||
-rw-r--r-- | src/command/PartitionCommands.hxx | 3 |
3 files changed, 46 insertions, 0 deletions
diff --git a/src/command/AllCommands.cxx b/src/command/AllCommands.cxx index 73ae9b4e7..8943f44e0 100644 --- a/src/command/AllCommands.cxx +++ b/src/command/AllCommands.cxx @@ -103,6 +103,7 @@ static constexpr struct command commands[] = { { "decoders", PERMISSION_READ, 0, 0, handle_decoders }, { "delete", PERMISSION_CONTROL, 1, 1, handle_delete }, { "deleteid", PERMISSION_CONTROL, 1, 1, handle_deleteid }, + { "delpartition", PERMISSION_ADMIN, 1, 1, handle_delpartition }, { "disableoutput", PERMISSION_ADMIN, 1, 1, handle_disableoutput }, { "enableoutput", PERMISSION_ADMIN, 1, 1, handle_enableoutput }, #ifdef ENABLE_DATABASE diff --git a/src/command/PartitionCommands.cxx b/src/command/PartitionCommands.cxx index bbb0e0143..fbcb8a754 100644 --- a/src/command/PartitionCommands.cxx +++ b/src/command/PartitionCommands.cxx @@ -113,6 +113,48 @@ handle_newpartition(Client &client, Request request, Response &response) } CommandResult +handle_delpartition(Client &client, Request request, Response &response) +{ + const char *name = request.front(); + if (!IsValidPartitionName(name)) { + response.Error(ACK_ERROR_ARG, "bad name"); + return CommandResult::ERROR; + } + + auto &instance = client.GetInstance(); + auto *partition = instance.FindPartition(name); + if (partition == nullptr) { + response.Error(ACK_ERROR_NO_EXIST, "no such partition"); + return CommandResult::ERROR; + } + + if (partition == &instance.partitions.front()) { + response.Error(ACK_ERROR_UNKNOWN, + "cannot delete the default partition"); + return CommandResult::ERROR; + } + + if (!partition->clients.empty()) { + response.Error(ACK_ERROR_UNKNOWN, + "partition still has clients"); + return CommandResult::ERROR; + } + + if (!partition->outputs.IsDummy()) { + response.Error(ACK_ERROR_UNKNOWN, + "partition still has outputs"); + return CommandResult::ERROR; + } + + partition->BeginShutdown(); + instance.DeletePartition(*partition); + + instance.EmitIdle(IDLE_PARTITION); + + return CommandResult::OK; +} + +CommandResult handle_moveoutput(Client &client, Request request, Response &response) { const char *output_name = request[0]; diff --git a/src/command/PartitionCommands.hxx b/src/command/PartitionCommands.hxx index c840c0a82..22ce5df8c 100644 --- a/src/command/PartitionCommands.hxx +++ b/src/command/PartitionCommands.hxx @@ -36,6 +36,9 @@ CommandResult handle_newpartition(Client &client, Request request, Response &response); CommandResult +handle_delpartition(Client &client, Request request, Response &response); + +CommandResult handle_moveoutput(Client &client, Request request, Response &response); #endif |