[pbs-devel] applied: [PATCH backup] client: allocate two fewer strings
Fabian Grünbichler
f.gruenbichler at proxmox.com
Mon Mar 17 16:10:53 CET 2025
thanks!
On March 10, 2025 11:43 am, Maximiliano Sandoval wrote:
> Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
> ---
>
> A small improvement I noticed while browsing the project.
>
> proxmox-backup-client/src/main.rs | 38 ++++++++++++++-----------------
> 1 file changed, 17 insertions(+), 21 deletions(-)
>
> diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs
> index 7fa57b2f..5a4dc76f 100644
> --- a/proxmox-backup-client/src/main.rs
> +++ b/proxmox-backup-client/src/main.rs
> @@ -827,40 +827,36 @@ async fn create_backup(
> let mut target_set = HashSet::new();
>
> for backupspec in backupspec_list {
> - let spec = parse_backup_specification(backupspec.as_str().unwrap())?;
> - let filename = &spec.config_string;
> - let target = &spec.archive_name;
> + let pbs_client::BackupSpecification {
> + archive_name: target,
> + config_string: filename,
> + spec_type,
> + } = parse_backup_specification(backupspec.as_str().unwrap())?;
>
> - if target_set.contains(target) {
> + if target_set.contains(&target) {
> bail!("got target twice: '{}'", target);
> }
> - target_set.insert(target.to_string());
> + target_set.insert(target.clone());
>
> use std::os::unix::fs::FileTypeExt;
>
> - let metadata = std::fs::metadata(filename)
> + let metadata = std::fs::metadata(&filename)
> .map_err(|err| format_err!("unable to access '{}' - {}", filename, err))?;
> let file_type = metadata.file_type();
>
> - match spec.spec_type {
> + match spec_type {
> BackupSpecificationType::PXAR => {
> if !file_type.is_dir() {
> bail!("got unexpected file type (expected directory)");
> }
> - upload_list.push((
> - BackupSpecificationType::PXAR,
> - filename.to_owned(),
> - target.to_owned(),
> - "didx",
> - 0,
> - ));
> + upload_list.push((BackupSpecificationType::PXAR, filename, target, "didx", 0));
> }
> BackupSpecificationType::IMAGE => {
> if !(file_type.is_file() || file_type.is_block_device()) {
> bail!("got unexpected file type (expected file or block device)");
> }
>
> - let size = image_size(&PathBuf::from(filename))?;
> + let size = image_size(&PathBuf::from(&filename))?;
>
> if size == 0 {
> bail!("got zero-sized file '{}'", filename);
> @@ -868,8 +864,8 @@ async fn create_backup(
>
> upload_list.push((
> BackupSpecificationType::IMAGE,
> - filename.to_owned(),
> - target.to_owned(),
> + filename,
> + target,
> "fidx",
> size,
> ));
> @@ -880,8 +876,8 @@ async fn create_backup(
> }
> upload_list.push((
> BackupSpecificationType::CONFIG,
> - filename.to_owned(),
> - target.to_owned(),
> + filename,
> + target,
> "blob",
> metadata.len(),
> ));
> @@ -892,8 +888,8 @@ async fn create_backup(
> }
> upload_list.push((
> BackupSpecificationType::LOGFILE,
> - filename.to_owned(),
> - target.to_owned(),
> + filename,
> + target,
> "blob",
> metadata.len(),
> ));
> --
> 2.39.5
>
>
>
> _______________________________________________
> pbs-devel mailing list
> pbs-devel at lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
>
>
>
More information about the pbs-devel
mailing list