pub unsafe fn setup(_build: &mut crate::Build) {}
}
+pub use crate::builder::PathSet;
use crate::cache::{Interned, INTERNER};
pub use crate::config::Config;
pub use crate::flags::Subcommand;
/// Copies a file from `src` to `dst`
pub fn copy(&self, src: &Path, dst: &Path) {
+ self.copy_internal(src, dst, false);
+ }
+
+ fn copy_internal(&self, src: &Path, dst: &Path, dereference_symlinks: bool) {
if self.config.dry_run {
return;
}
}
let _ = fs::remove_file(&dst);
let metadata = t!(src.symlink_metadata());
+ let mut src = src.to_path_buf();
if metadata.file_type().is_symlink() {
- let link = t!(fs::read_link(src));
- t!(symlink_file(link, dst));
- } else if let Ok(()) = fs::hard_link(src, dst) {
+ if dereference_symlinks {
+ src = t!(fs::canonicalize(src));
+ } else {
+ let link = t!(fs::read_link(src));
+ t!(symlink_file(link, dst));
+ return;
+ }
+ }
+ if let Ok(()) = fs::hard_link(&src, dst) {
// Attempt to "easy copy" by creating a hard link
// (symlinks don't work on windows), but if that fails
// just fall back to a slow `copy` operation.
} else {
- if let Err(e) = fs::copy(src, dst) {
+ if let Err(e) = fs::copy(&src, dst) {
panic!("failed to copy `{}` to `{}`: {}", src.display(), dst.display(), e)
}
t!(fs::set_permissions(dst, metadata.permissions()));
let dst = dstdir.join(src.file_name().unwrap());
self.verbose_than(1, &format!("Install {:?} to {:?}", src, dst));
t!(fs::create_dir_all(dstdir));
- drop(fs::remove_file(&dst));
- {
- if !src.exists() {
- panic!("Error: File \"{}\" not found!", src.display());
- }
- let metadata = t!(src.symlink_metadata());
- if let Err(e) = fs::copy(&src, &dst) {
- panic!("failed to copy `{}` to `{}`: {}", src.display(), dst.display(), e)
- }
- t!(fs::set_permissions(&dst, metadata.permissions()));
- let atime = FileTime::from_last_access_time(&metadata);
- let mtime = FileTime::from_last_modification_time(&metadata);
- t!(filetime::set_file_times(&dst, atime, mtime));
+ if !src.exists() {
+ panic!("Error: File \"{}\" not found!", src.display());
}
+ self.copy_internal(src, &dst, true);
chmod(&dst, perms);
}