From 0ef17ca2ecb9554bd2256cf6ae68be1e335e98d1 Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Sat, 16 Dec 2023 18:49:44 -0500 Subject: [PATCH] Add test for extracting symlink nodes and fix behavior --- src/node.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/node.rs b/src/node.rs index cda14b3..90f7c12 100644 --- a/src/node.rs +++ b/src/node.rs @@ -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")); + } }