about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorEdward Barnard <eabarnard@gmail.com>2019-03-04 12:35:46 +0000
committerEdward Barnard <eabarnard@gmail.com>2019-03-04 12:35:46 +0000
commit0a991e424a794d0d556602e88cd2ebf511b05de7 (patch)
treeb48d7bcbbfffb9addddfeea07d5492a2eda5dea1 /src/libstd
parentc82a42c155aa4b4825cb8dc21e9e498a752af13f (diff)
downloadrust-0a991e424a794d0d556602e88cd2ebf511b05de7.tar.gz
rust-0a991e424a794d0d556602e88cd2ebf511b05de7.zip
Add test for the behaviour of `fs::copy` when `to` is a symlink
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/fs.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs
index 3454f847ef4..7b9b5d4de20 100644
--- a/src/libstd/fs.rs
+++ b/src/libstd/fs.rs
@@ -2838,6 +2838,26 @@ mod tests {
     }
 
     #[test]
+    fn copy_file_follows_dst_symlink() {
+        let tmp = tmpdir();
+        if !got_symlink_permission(&tmp) { return };
+
+        let in_path = tmp.join("in.txt");
+        let out_path = tmp.join("out.txt");
+        let out_path_symlink = tmp.join("out_symlink.txt");
+
+        check!(fs::write(&in_path, "foo"));
+        check!(fs::write(&out_path, "bar"));
+        check!(symlink_file(&out_path, &out_path_symlink));
+
+        check!(fs::copy(&in_path, &out_path_symlink));
+
+        assert!(check!(out_path_symlink.symlink_metadata()).file_type().is_symlink());
+        assert_eq!(check!(fs::read(&out_path_symlink)), b"foo".to_vec());
+        assert_eq!(check!(fs::read(&out_path)), b"foo".to_vec());
+    }
+
+    #[test]
     fn symlinks_work() {
         let tmpdir = tmpdir();
         if !got_symlink_permission(&tmpdir) { return };