mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-22 13:38:43 +00:00
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:
parent
5506ffb5d0
commit
5b4909f9eb
1 changed files with 9 additions and 3 deletions
12
src/bins.rs
12
src/bins.rs
|
@ -1,4 +1,6 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use cargo_toml::Product;
|
use cargo_toml::Product;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
@ -102,15 +104,19 @@ impl BinFile {
|
||||||
std::fs::remove_file(&self.link)?;
|
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!(
|
debug!(
|
||||||
"Create link '{}' pointing to '{}'",
|
"Create link '{}' pointing to '{}'",
|
||||||
self.link.display(),
|
self.link.display(),
|
||||||
self.dest.display()
|
dest.display()
|
||||||
);
|
);
|
||||||
#[cfg(target_family = "unix")]
|
#[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")]
|
#[cfg(target_family = "windows")]
|
||||||
std::os::windows::fs::symlink_file(&self.dest, &self.link)?;
|
std::os::windows::fs::symlink_file(dest, &self.link)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue