]> git.lizzy.rs Git - rust.git/commitdiff
Add test for the behaviour of `fs::copy` when `to` is a symlink
authorEdward Barnard <eabarnard@gmail.com>
Mon, 4 Mar 2019 12:35:46 +0000 (12:35 +0000)
committerEdward Barnard <eabarnard@gmail.com>
Mon, 4 Mar 2019 12:35:46 +0000 (12:35 +0000)
src/libstd/fs.rs

index 3454f847ef41461e032d79fc9b7aaf546a9f155c..7b9b5d4de206ca88c3fc95c3fff917569a79bb76 100644 (file)
@@ -2837,6 +2837,26 @@ fn copy_file_returns_metadata_len() {
         assert_eq!(check!(out_path.metadata()).len(), copied_len);
     }
 
+    #[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();