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
This commit is contained in:
наб 2022-03-13 16:23:12 +01:00
parent 5506ffb5d0
commit 5b4909f9eb
No known key found for this signature in database
GPG key ID: BCFD0B018D2658F1

View file

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