all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Maximiliano Sandoval <m.sandoval@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH backup] client: allocate two fewer strings
Date: Mon, 10 Mar 2025 11:43:18 +0100	[thread overview]
Message-ID: <20250310104318.222927-1-m.sandoval@proxmox.com> (raw)

Signed-off-by: Maximiliano Sandoval <m.sandoval@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@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


             reply	other threads:[~2025-03-10 10:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-10 10:43 Maximiliano Sandoval [this message]
2025-03-17 15:10 ` [pbs-devel] applied: " Fabian Grünbichler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250310104318.222927-1-m.sandoval@proxmox.com \
    --to=m.sandoval@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal