Skip to content

Commit c4a6a6c

Browse files
committed
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.
1 parent ea9259c commit c4a6a6c

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/rustup-utils/src/utils.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,24 @@ pub fn copy_dir(src: &Path, dest: &Path, notify_handler: &Fn(Notification)) -> R
299299
}
300300

301301
pub fn copy_file(src: &Path, dest: &Path) -> Result<()> {
302-
fs::copy(src, dest)
303-
.chain_err(|| ErrorKind::CopyingFile {
304-
src: PathBuf::from(src),
305-
dest: PathBuf::from(dest),
306-
})
307-
.map(|_| ())
302+
let metadata = fs::symlink_metadata(src).chain_err(|| ErrorKind::ReadingFile {
303+
name: "metadata for",
304+
path: PathBuf::from(src),
305+
})?;
306+
if metadata.file_type().is_symlink() {
307+
let link = fs::read_link(src).chain_err(|| ErrorKind::ReadingFile {
308+
name: "link contents for",
309+
path: PathBuf::from(src),
310+
})?;
311+
symlink_file(&link, dest).map(|_| ())
312+
} else {
313+
fs::copy(src, dest)
314+
.chain_err(|| ErrorKind::CopyingFile {
315+
src: PathBuf::from(src),
316+
dest: PathBuf::from(dest),
317+
})
318+
.map(|_| ())
319+
}
308320
}
309321

310322
pub fn remove_dir(

0 commit comments

Comments
 (0)