Skip to content

Commit 14c6716

Browse files
committed
Copy symlinks
lldb includes some symlinks in its install tree, and so generator must copy these symlinks as well. I believe only file symlinks are needed.
1 parent 74c2f5a commit 14c6716

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/util.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ use walkdir::WalkDir;
1818
use std::os::unix::fs::OpenOptionsExt;
1919
// FIXME: what about Windows? Are default ACLs executable?
2020

21+
#[cfg(unix)]
22+
use std::os::unix::fs::symlink as symlink_file;
23+
#[cfg(windows)]
24+
use std::os::windows::fs::symlink_file;
25+
2126
use errors::*;
2227

2328
/// Convert a `&Path` to a UTF-8 `&str`
@@ -29,9 +34,15 @@ pub fn path_to_str(path: &Path) -> Result<&str> {
2934

3035
/// Wrap `fs::copy` with a nicer error message
3136
pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<u64> {
32-
fs::copy(&from, &to)
33-
.chain_err(|| format!("failed to copy '{}' to '{}'",
34-
from.as_ref().display(), to.as_ref().display()))
37+
if fs::symlink_metadata(&from)?.file_type().is_symlink() {
38+
let link = fs::read_link(&from)?;
39+
symlink_file(link, &to)?;
40+
Ok(0)
41+
} else {
42+
fs::copy(&from, &to)
43+
.chain_err(|| format!("failed to copy '{}' to '{}'",
44+
from.as_ref().display(), to.as_ref().display()))
45+
}
3546
}
3647

3748
/// Wrap `fs::create_dir` with a nicer error message

0 commit comments

Comments
 (0)