namespaces: move max-depth check to api type

and use it when creating a sync job, and simplify the check on updating
(only check the final, resulting config instead of each intermediate
version).

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler
2022-05-13 11:25:01 +02:00
parent 11567dfbad
commit 66abc4cb7d
3 changed files with 32 additions and 28 deletions

View File

@ -719,6 +719,17 @@ impl BackupNamespace {
}
Ok(new)
}
/// Check whether adding `depth` levels of sub-namespaces exceeds the max depth limit
pub fn check_max_depth(&self, depth: usize) -> Result<(), Error> {
let ns_depth = self.depth();
if ns_depth + depth > MAX_NAMESPACE_DEPTH {
bail!(
"namespace '{self}'s depth and recursion depth exceed limit: {ns_depth} + {depth} > {MAX_NAMESPACE_DEPTH}",
);
}
Ok(())
}
}
impl fmt::Display for BackupNamespace {