Skip to content

Commit

Permalink
Merge pull request rust-lang#1504 from tromey/preserve-symlinks
Browse files Browse the repository at this point in the history
Preserve symlinks when installing
  • Loading branch information
nrc authored Sep 18, 2018
2 parents c3e4ce4 + c4a6a6c commit e262938
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/rustup-utils/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,24 @@ pub fn copy_dir(src: &Path, dest: &Path, notify_handler: &Fn(Notification)) -> R
}

pub fn copy_file(src: &Path, dest: &Path) -> Result<()> {
fs::copy(src, dest)
.chain_err(|| ErrorKind::CopyingFile {
src: PathBuf::from(src),
dest: PathBuf::from(dest),
})
.map(|_| ())
let metadata = fs::symlink_metadata(src).chain_err(|| ErrorKind::ReadingFile {
name: "metadata for",
path: PathBuf::from(src),
})?;
if metadata.file_type().is_symlink() {
let link = fs::read_link(src).chain_err(|| ErrorKind::ReadingFile {
name: "link contents for",
path: PathBuf::from(src),
})?;
symlink_file(&link, dest).map(|_| ())
} else {
fs::copy(src, dest)
.chain_err(|| ErrorKind::CopyingFile {
src: PathBuf::from(src),
dest: PathBuf::from(dest),
})
.map(|_| ())
}
}

pub fn remove_dir(
Expand Down

0 comments on commit e262938

Please sign in to comment.