namespace deletion: make destroying groups separate choice

And make that opt-in in the API endpoint, to avoid bad surprises by
default.

If not set we'll only prune empty namespaces.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht
2022-05-15 13:50:58 +02:00
parent 4ac8ec11fb
commit d1f9cceada
3 changed files with 37 additions and 16 deletions

View File

@ -134,6 +134,13 @@ pub fn list_namespaces(
ns: {
type: BackupNamespace,
},
"delete-groups": {
type: bool,
description: "If set, all groups will be destroyed in the whole hierachy below and\
including `ns`. If not set, only empty namespaces will be pruned.",
optional: true,
default: false,
},
},
},
access: {
@ -144,6 +151,7 @@ pub fn list_namespaces(
pub fn delete_namespace(
store: String,
ns: BackupNamespace,
delete_groups: bool,
_info: &ApiMethod,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
@ -159,7 +167,7 @@ pub fn delete_namespace(
let datastore = DataStore::lookup_datastore(&store, Some(Operation::Write))?;
if !datastore.remove_namespace_recursive(&ns)? {
if !datastore.remove_namespace_recursive(&ns, delete_groups)? {
bail!("group only partially deleted due to protected snapshots");
}

View File

@ -864,7 +864,7 @@ fn check_and_remove_ns(params: &PullParameters, local_ns: &BackupNamespace) -> R
&params.owner,
PRIV_DATASTORE_MODIFY,
)?;
params.store.remove_namespace_recursive(local_ns)
params.store.remove_namespace_recursive(local_ns, true)
}
fn check_and_remove_vanished_ns(