api-types: rework BackupNamespace::map_prefix
to use slice::strip_prefix() from std Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com> Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
53d073ec1a
commit
6b4d057370
|
@ -702,25 +702,22 @@ impl BackupNamespace {
|
||||||
source_prefix: &BackupNamespace,
|
source_prefix: &BackupNamespace,
|
||||||
target_prefix: &BackupNamespace,
|
target_prefix: &BackupNamespace,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let mut mapped = target_prefix.clone();
|
let suffix = self
|
||||||
let mut source_iter = source_prefix.components();
|
.inner
|
||||||
let mut self_iter = self.components();
|
.strip_prefix(&source_prefix.inner[..])
|
||||||
|
.ok_or_else(|| {
|
||||||
while let Some(comp) = self_iter.next() {
|
format_err!(
|
||||||
if let Some(source_comp) = source_iter.next() {
|
|
||||||
if source_comp != comp {
|
|
||||||
bail!(
|
|
||||||
"Failed to map namespace - {} is not a valid prefix of {}",
|
"Failed to map namespace - {} is not a valid prefix of {}",
|
||||||
source_prefix,
|
source_prefix,
|
||||||
self
|
self
|
||||||
);
|
)
|
||||||
}
|
})?;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
mapped.push(comp.to_owned())?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(mapped)
|
let mut new = target_prefix.clone();
|
||||||
|
for item in suffix {
|
||||||
|
new.push(item.clone())?;
|
||||||
|
}
|
||||||
|
Ok(new)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue