Skip to content

Commit 0a991e4

Browse files
committed
Add test for the behaviour of fs::copy when to is a symlink
1 parent c82a42c commit 0a991e4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/libstd/fs.rs

+20
Original file line numberDiff line numberDiff line change
@@ -2837,6 +2837,26 @@ mod tests {
28372837
assert_eq!(check!(out_path.metadata()).len(), copied_len);
28382838
}
28392839

2840+
#[test]
2841+
fn copy_file_follows_dst_symlink() {
2842+
let tmp = tmpdir();
2843+
if !got_symlink_permission(&tmp) { return };
2844+
2845+
let in_path = tmp.join("in.txt");
2846+
let out_path = tmp.join("out.txt");
2847+
let out_path_symlink = tmp.join("out_symlink.txt");
2848+
2849+
check!(fs::write(&in_path, "foo"));
2850+
check!(fs::write(&out_path, "bar"));
2851+
check!(symlink_file(&out_path, &out_path_symlink));
2852+
2853+
check!(fs::copy(&in_path, &out_path_symlink));
2854+
2855+
assert!(check!(out_path_symlink.symlink_metadata()).file_type().is_symlink());
2856+
assert_eq!(check!(fs::read(&out_path_symlink)), b"foo".to_vec());
2857+
assert_eq!(check!(fs::read(&out_path)), b"foo".to_vec());
2858+
}
2859+
28402860
#[test]
28412861
fn symlinks_work() {
28422862
let tmpdir = tmpdir();

0 commit comments

Comments
 (0)