]> git.proxmox.com Git - pve-installer.git/commitdiff
print paths directly with debug, not display
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 19 Apr 2024 16:06:14 +0000 (18:06 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 22 Apr 2024 12:31:37 +0000 (14:31 +0200)
A debug print is not only shorter code but also quotes the path
correctly, making it nicer for the user to copy (e.g., if the path is
at the end of a sentence the trailing dot could be misinterpreted as
being part of the path otherwise)

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
proxmox-auto-install-assistant/src/main.rs
proxmox-chroot/src/main.rs
proxmox-fetch-answer/src/fetch_plugins/partition.rs

index 92d5aa28fc31b56e4ea299dfac494169a2ae320c..da55cf6bd6bc8086f735a1171406d9dfecdcc0ac 100644 (file)
@@ -356,11 +356,12 @@ fn final_iso_location(args: &CommandPrepareISO) -> PathBuf {
         return specified;
     }
     let mut suffix: String = match args.install_mode {
-        AutoInstModes::Auto => "auto".into(),
-        AutoInstModes::Http => "auto-http".into(),
-        AutoInstModes::Included => "auto-answer-included".into(),
-        AutoInstModes::Partition => "auto-part".into(),
-    };
+        AutoInstModes::Auto => "auto",
+        AutoInstModes::Http => "auto-http",
+        AutoInstModes::Included => "auto-answer-included",
+        AutoInstModes::Partition => "auto-part",
+    }
+    .into();
 
     if args.url.is_some() {
         suffix.push_str("-url");
@@ -391,10 +392,8 @@ fn inject_file_to_iso(iso: &PathBuf, file: &PathBuf, location: &str) -> Result<(
         .output()?;
     if !result.status.success() {
         bail!(
-            "Error injecting {} into {}: {}",
-            file.display(),
-            iso.display(),
-            String::from_utf8(result.stderr)?
+            "Error injecting {file:?} into {iso:?}: {}",
+            String::from_utf8_lossy(&result.stderr)
         );
     }
     Ok(())
@@ -510,7 +509,7 @@ fn get_udev_properties(path: &PathBuf) -> Result<String> {
         .arg("all")
         .output()?;
     if !udev_output.status.success() {
-        bail!("could not run udevadm successfully for {}", path.display());
+        bail!("could not run udevadm successfully for {path:?}");
     }
     Ok(String::from_utf8(udev_output.stdout)?)
 }
@@ -518,11 +517,11 @@ fn get_udev_properties(path: &PathBuf) -> Result<String> {
 fn parse_answer(path: &PathBuf) -> Result<Answer> {
     let mut file = match fs::File::open(path) {
         Ok(file) => file,
-        Err(err) => bail!("Opening answer file '{}' failed: {err}", path.display()),
+        Err(err) => bail!("Opening answer file {path:?} failed: {err}"),
     };
     let mut contents = String::new();
     if let Err(err) = file.read_to_string(&mut contents) {
-        bail!("Reading from file '{}' failed: {err}", path.display());
+        bail!("Reading from file {path:?} failed: {err}");
     }
     match toml::from_str(&contents) {
         Ok(answer) => {
index c1a4785a109064907ab94df4d7a67fc7a9be8806..ca6f3a9076713cc4fb398486715766915bae03f7 100644 (file)
@@ -305,7 +305,7 @@ fn bindmount() -> Result<()> {
         let source = path::Path::new("/").join(item);
         let target = path::Path::new(TARGET_DIR).join(item);
 
-        println!("Bindmount {} to {}", source.display(), target.display());
+        println!("Bindmount {source:?} to {target:?}");
         mount(Some(source.as_path()), target.as_path(), NONE, flags, NONE)?;
     }
 
@@ -313,14 +313,10 @@ fn bindmount() -> Result<()> {
     if answer_path.exists() {
         let target = path::Path::new(TARGET_DIR).join("mnt").join(ANSWER_MP);
 
-        println!("Create dir {}", target.display());
+        println!("Create dir {target:?}");
         fs::create_dir_all(&target)?;
 
-        println!(
-            "Bindmount {} to {}",
-            answer_path.display(),
-            target.display()
-        );
+        println!("Bindmount {answer_path:?} to {target:?}");
         mount(
             Some(answer_path.as_path()),
             target.as_path(),
@@ -335,7 +331,7 @@ fn bindmount() -> Result<()> {
 fn bind_umount() -> Result<()> {
     for item in BINDMOUNTS {
         let target = path::Path::new(TARGET_DIR).join(item);
-        println!("Unmounting {}", target.display());
+        println!("Unmounting {target:?}");
         if let Err(e) = umount(target.as_path()) {
             eprintln!("{e}");
         }
index 6993709a712ab074415381bd0138da7d245a3d66..e8e256b7fbfab4a15f47b3907998c7271068b418 100644 (file)
@@ -43,7 +43,7 @@ fn scan_partlabels(partlabel_source: &str, search_path: &str) -> Result<PathBuf>
             return Ok(path);
         }
         Ok(false) => info!("Did not detect partition with label '{partlabel}'"),
-        Err(err) => info!("Encountered issue, accessing '{}': {err}", path.display()),
+        Err(err) => info!("Encountered issue, accessing '{path:?}': {err}"),
     }
 
     let partlabel = partlabel_source.to_lowercase();
@@ -54,7 +54,7 @@ fn scan_partlabels(partlabel_source: &str, search_path: &str) -> Result<PathBuf>
             return Ok(path);
         }
         Ok(false) => info!("Did not detect partition with label '{partlabel}'"),
-        Err(err) => info!("Encountered issue, accessing '{}': {err}", path.display()),
+        Err(err) => info!("Encountered issue, accessing '{path:?}': {err}"),
     }
     Err(Error::msg(format!(
         "Could not detect upper or lower case labels for '{partlabel_source}'"