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] 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(()) }