Skip to content

Commit

Permalink
Test that renaming symlinks preserves the symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDenton committed Dec 27, 2024
1 parent a867086 commit c0c2118
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions library/std/src/fs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1959,9 +1959,12 @@ fn test_rename_symlink() {
let tmpdir = tmpdir();
let original = tmpdir.join("original");
let dest = tmpdir.join("dest");
let not_exist = Path::new("does not exist");

symlink_file("does not exist", &original).unwrap();
symlink_file(not_exist, &original).unwrap();
fs::rename(&original, &dest).unwrap();
// Make sure that copying `original` to `dest` preserves the symlink.
assert_eq!(fs::read_link(&dest).unwrap().as_path(), not_exist);
}

#[test]
Expand All @@ -1970,7 +1973,12 @@ fn test_rename_junction() {
let tmpdir = tmpdir();
let original = tmpdir.join("original");
let dest = tmpdir.join("dest");
let not_exist = Path::new("does not exist");

junction_point("does not exist", &original).unwrap();
junction_point(&not_exist, &original).unwrap();
fs::rename(&original, &dest).unwrap();

// Make sure that copying `original`` to `dest` preserves the junction point.
// Junction links are always absolute so we just check the file name is correct.
assert_eq!(fs::read_link(&dest).unwrap().file_name(), Some(not_exist.as_os_str()));
}

0 comments on commit c0c2118

Please sign in to comment.