Skip to content

Commit 3de05f6

Browse files
committed
fix: unexpected abort when symlink to non-regular file
1 parent 10d691d commit 3de05f6

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

rye/src/utils/mod.rs

+33
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,39 @@ pub fn copy_dir<T: AsRef<Path>>(from: T, to: T, options: &CopyDirOptions) -> Res
453453
fs::create_dir_all(&destination)
454454
.path_context(&destination, "failed to create directory")?;
455455
copy_dir(entry.path(), destination, options)?;
456+
} else if entry.file_type()?.is_symlink() {
457+
let target = fs::read_link(&entry_path)
458+
.path_context(&entry_path, "failed to read symlink target")?;
459+
#[cfg(unix)]
460+
{
461+
if target.is_absolute() && target.starts_with(from) {
462+
symlink_file(target.strip_prefix(from).unwrap(), &destination)
463+
.path_context(&destination, "failed to create symlink")?;
464+
} else {
465+
symlink_file(target, &destination)
466+
.path_context(&destination, "failed to create symlink")?;
467+
}
468+
}
469+
#[cfg(windows)]
470+
{
471+
if target.is_absolute() && target.starts_with(from) {
472+
if target.is_dir() {
473+
symlink_dir(target.strip_prefix(from).unwrap(), &destination)
474+
.path_context(&destination, "failed to create symlink")?;
475+
} else {
476+
symlink_file(target.strip_prefix(from).unwrap(), &destination)
477+
.path_context(&destination, "failed to create symlink")?;
478+
}
479+
} else {
480+
if target.is_dir() {
481+
symlink_dir(target, &destination)
482+
.path_context(&destination, "failed to create symlink")?;
483+
} else {
484+
symlink_file(target, &destination)
485+
.path_context(&destination, "failed to create symlink")?;
486+
}
487+
}
488+
}
456489
} else {
457490
fs::copy(entry.path(), &destination)
458491
.path_context(entry.path(), "failed to copy file")?;

0 commit comments

Comments
 (0)