From c4a6a6c4854c5d491f7171025be6303396546b5d Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 14 Sep 2018 05:16:46 -0600 Subject: [PATCH] Preserve symlinks when installing The lldb-preview component includes symlinks. Currently, rustup changes these to be regular files while installing. This then causes the resulting lldb to load liblldb twice, which causes a crash at startup, because command line options are registered twice. This changes rustup to preserve symlinks when installing. --- src/rustup-utils/src/utils.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/rustup-utils/src/utils.rs b/src/rustup-utils/src/utils.rs index 5d7c24b2af..238e179216 100644 --- a/src/rustup-utils/src/utils.rs +++ b/src/rustup-utils/src/utils.rs @@ -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(