Skip to content

Commit

Permalink
Merge pull request #951 from malbarbo/symlink
Browse files Browse the repository at this point in the history
Add fallback to symlink if hardlink fails
  • Loading branch information
Diggsey authored Feb 11, 2017
2 parents 56042d7 + eeb1a6a commit 408ed84
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/rustup-cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,13 @@ fn install_bins() -> Result<()> {
try!(utils::copy_file(this_exe_path, rustup_path));
try!(utils::make_executable(rustup_path));

// Hardlink all the Rust exes to the rustup exe. Using hardlinks
// because they work on Windows.
// Try to hardlink all the Rust exes to the rustup exe. Some systems,
// like Android, does not support hardlinks, so we fallback to symlinks.
for tool in TOOLS {
let ref tool_path = bin_path.join(&format!("{}{}", tool, EXE_SUFFIX));
try!(utils::hardlink_file(rustup_path, tool_path))
if utils::hardlink_file(rustup_path, tool_path).is_err() {
try!(utils::symlink_file(rustup_path, tool_path))
}
}

Ok(())
Expand Down
20 changes: 20 additions & 0 deletions src/rustup-utils/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,26 @@ pub fn hardlink_file(src: &Path, dest: &Path) -> Result<()> {
})
}

#[cfg(unix)]
pub fn symlink_file(src: &Path, dest: &Path) -> Result<()> {
::std::os::unix::fs::symlink(src, dest).chain_err(|| {
ErrorKind::LinkingFile {
src: PathBuf::from(src),
dest: PathBuf::from(dest),
}
})
}

#[cfg(windows)]
pub fn symlink_file(src: &Path, dest: &Path) -> Result<()> {
// we are supposed to not use symlink on windows
Err(ErrorKind::LinkingFile {
src: PathBuf::from(src),
dest: PathBuf::from(dest),
}.into()
)
}

pub fn copy_dir(src: &Path, dest: &Path, notify_handler: &Fn(Notification)) -> Result<()> {
notify_handler(Notification::CopyingDirectory(src, dest));
raw::copy_dir(src, dest).chain_err(|| {
Expand Down

0 comments on commit 408ed84

Please sign in to comment.