Add test for extracting symlink nodes and fix behavior

This commit is contained in:
Nathan Fisher 2023-12-16 18:49:44 -05:00
parent b534cf6d49
commit 0ef17ca2ec
1 changed files with 15 additions and 1 deletions

View File

@ -286,7 +286,10 @@ impl Node {
fs::hard_link(target, &path)?;
}
FileType::SoftLink(ref t) => {
symlink(&self.name, t)?;
if n_path.exists() {
fs::remove_file(&n_path)?;
}
symlink(t, &n_path)?;
}
FileType::Directory => {
self.mkdir(&PathBuf::from(&path))?;
@ -528,4 +531,15 @@ mod tests {
let f = fs::read_to_string("test/output/test/li.txt").unwrap();
assert_eq!(f.as_bytes(), LI);
}
#[test]
fn extract_symlink() {
let links = Mutex::new(HashMap::new());
let _res = remove_file("test/lilnk.txt");
symlink("li.txt", "test/lilnk.txt").unwrap();
let node = Node::from_path("test/lilnk.txt", Algorithm::Md5, &links).unwrap();
node.extract(Some("test/output")).unwrap();
let tgt = fs::read_link("test/output/test/lilnk.txt").unwrap();
assert_eq!(tgt, PathBuf::from("li.txt"));
}
}