api: tape/restore: check and create target namespace

checks the privilegs for the target namespace. If that does not exist,
try to recursively create them while checking the privileges.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak
2022-05-06 16:44:16 +02:00
parent 6b61d319c5
commit fc99c2791b
3 changed files with 124 additions and 12 deletions

View File

@ -386,10 +386,7 @@ impl DataStore {
parent: &BackupNamespace,
name: String,
) -> Result<BackupNamespace, Error> {
let mut parent_path = self.base_path().to_owned();
parent_path.push(parent.path());
if !parent_path.exists() {
if !self.namespace_exists(parent) {
bail!("cannot create new namespace, parent {parent} doesn't already exists");
}
@ -404,6 +401,13 @@ impl DataStore {
Ok(ns)
}
/// Returns if the given namespace exists on the datastore
pub fn namespace_exists(&self, ns: &BackupNamespace) -> bool {
let mut path = self.base_path().to_owned();
path.push(ns.path());
path.exists()
}
/// Remove all backup groups of a single namespace level but not the namespace itself.
///
/// Does *not* descends into child-namespaces and doesn't remoes the namespace itself either.