tools::format: avoid some string copies
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
5b17a02da4
commit
d7eedbd24b
|
@ -338,7 +338,7 @@ impl BackupWriter {
|
|||
let size_dirty = upload_stats.size - upload_stats.size_reused;
|
||||
let size: HumanByte = upload_stats.size.into();
|
||||
let archive = if self.verbose {
|
||||
archive_name.to_string()
|
||||
archive_name
|
||||
} else {
|
||||
pbs_tools::format::strip_server_file_extension(archive_name)
|
||||
};
|
||||
|
|
|
@ -306,7 +306,7 @@ pub async fn complete_server_file_name_do(param: &HashMap<String, String>) -> Ve
|
|||
pub fn complete_archive_name(arg: &str, param: &HashMap<String, String>) -> Vec<String> {
|
||||
complete_server_file_name(arg, param)
|
||||
.iter()
|
||||
.map(|v| pbs_tools::format::strip_server_file_extension(&v))
|
||||
.map(|v| pbs_tools::format::strip_server_file_extension(&v).to_owned())
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
@ -315,7 +315,7 @@ pub fn complete_pxar_archive_name(arg: &str, param: &HashMap<String, String>) ->
|
|||
.iter()
|
||||
.filter_map(|name| {
|
||||
if name.ends_with(".pxar.didx") {
|
||||
Some(pbs_tools::format::strip_server_file_extension(name))
|
||||
Some(pbs_tools::format::strip_server_file_extension(name).to_owned())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -328,7 +328,7 @@ pub fn complete_img_archive_name(arg: &str, param: &HashMap<String, String>) ->
|
|||
.iter()
|
||||
.filter_map(|name| {
|
||||
if name.ends_with(".img.fidx") {
|
||||
Some(pbs_tools::format::strip_server_file_extension(name))
|
||||
Some(pbs_tools::format::strip_server_file_extension(name).to_owned())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
use std::borrow::Borrow;
|
||||
|
||||
use anyhow::{Error};
|
||||
use serde_json::Value;
|
||||
|
||||
pub fn strip_server_file_extension(name: &str) -> String {
|
||||
pub fn strip_server_file_extension(name: &str) -> &str {
|
||||
if name.ends_with(".didx") || name.ends_with(".fidx") || name.ends_with(".blob") {
|
||||
name[..name.len()-5].to_owned()
|
||||
&name[..name.len()-5]
|
||||
} else {
|
||||
name.to_owned() // should not happen
|
||||
name // should not happen
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_backup_file_list(files: &[String]) -> String {
|
||||
let mut files: Vec<String> = files.iter()
|
||||
.map(|v| strip_server_file_extension(&v))
|
||||
pub fn render_backup_file_list<S: Borrow<str>>(files: &[S]) -> String {
|
||||
let mut files: Vec<&str> = files.iter()
|
||||
.map(|v| strip_server_file_extension(v.borrow()))
|
||||
.collect();
|
||||
|
||||
files.sort();
|
||||
|
|
Loading…
Reference in New Issue