From 5b4909f9eb951ed9e103dda6f6f919a458f2e357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Sun, 13 Mar 2022 16:23:12 +0100 Subject: [PATCH 1/2] Link to basename instead of absolute path on unix This renders the link (a) more likely to fit in an ext4 inode and more importantly (b) makes the bindir impervious to being moved around --- src/bins.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/bins.rs b/src/bins.rs index c5ded440..beb74587 100644 --- a/src/bins.rs +++ b/src/bins.rs @@ -1,4 +1,6 @@ use std::path::PathBuf; +#[cfg(target_family = "unix")] +use std::path::Path; use cargo_toml::Product; use log::debug; @@ -102,15 +104,19 @@ impl BinFile { std::fs::remove_file(&self.link)?; } + #[cfg(target_family = "unix")] + let dest = &Path::new(self.dest.file_name().unwrap()); + #[cfg(target_family = "windows")] + let dest = &self.dest; debug!( "Create link '{}' pointing to '{}'", self.link.display(), - self.dest.display() + dest.display() ); #[cfg(target_family = "unix")] - std::os::unix::fs::symlink(&self.dest, &self.link)?; + std::os::unix::fs::symlink(dest, &self.link)?; #[cfg(target_family = "windows")] - std::os::windows::fs::symlink_file(&self.dest, &self.link)?; + std::os::windows::fs::symlink_file(dest, &self.link)?; Ok(()) } From f76791b9b93c65cd77fa08975813197ac80026bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Sun, 13 Mar 2022 16:29:15 +0100 Subject: [PATCH 2/2] Direct the symlink the right way in symlink info!(), point at actual destination --- src/bins.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/bins.rs b/src/bins.rs index beb74587..ce51dffe 100644 --- a/src/bins.rs +++ b/src/bins.rs @@ -1,6 +1,4 @@ -use std::path::PathBuf; -#[cfg(target_family = "unix")] -use std::path::Path; +use std::path::{PathBuf, Path}; use cargo_toml::Product; use log::debug; @@ -72,8 +70,8 @@ impl BinFile { format!( "{} ({} -> {})", self.base_name, - self.dest.display(), - self.link.display() + self.link.display(), + self.link_dest().display() ) } @@ -104,10 +102,7 @@ impl BinFile { std::fs::remove_file(&self.link)?; } - #[cfg(target_family = "unix")] - let dest = &Path::new(self.dest.file_name().unwrap()); - #[cfg(target_family = "windows")] - let dest = &self.dest; + let dest = self.link_dest(); debug!( "Create link '{}' pointing to '{}'", self.link.display(), @@ -120,6 +115,13 @@ impl BinFile { Ok(()) } + + fn link_dest(&self) -> &Path { + #[cfg(target_family = "unix")] + { Path::new(self.dest.file_name().unwrap()) } + #[cfg(target_family = "windows")] + { &self.dest } + } } /// Data required to get bin paths