diff --git a/src/node.rs b/src/node.rs index 3d5548a..f992755 100644 --- a/src/node.rs +++ b/src/node.rs @@ -313,6 +313,7 @@ impl Node { #[cfg(test)] mod tests { use super::*; + use core::panic; use std::{fmt::Write, fs::remove_file}; static LI: &[u8] = include_bytes!("../test/li.txt"); @@ -456,7 +457,7 @@ mod tests { assert_eq!(tgt, "li.txt"); node.write(&mut writer).unwrap(); } - let fd = std::fs::File::open("test/lilnk.node").unwrap(); + let fd = fs::File::open("test/lilnk.node").unwrap(); let mut reader = BufReader::new(fd); let node = Node::read(&mut reader).unwrap(); let FileType::SoftLink(ref tgt) = node.filetype else { @@ -466,6 +467,34 @@ mod tests { assert_eq!(tgt, "li.txt"); } + #[test] + fn load_store_hardlink() { + { + let _res = remove_file("test/lihlnk.txt"); + fs::hard_link("test/li.txt", "test/lihlnk.txt").unwrap(); + let _res = remove_file("test/lihlnk.node"); + let fd = std::fs::File::create("test/lihlnk.node").unwrap(); + let mut writer = std::io::BufWriter::new(fd); + let links = Mutex::new(HashMap::new()); + let _node = Node::from_path("test/li.txt", Algorithm::Sha1, &links).unwrap(); + let node = Node::from_path("test/lihlnk.txt", Algorithm::Sha1, &links).unwrap(); + let FileType::HardLink(ref tgt) = node.filetype else { + eprintln!("Created wrong filetype: {:?}", node.filetype); + panic!(); + }; + assert_eq!(tgt, "test/li.txt"); + node.write(&mut writer).unwrap(); + } + let fd = fs::File::open("test/lihlnk.node").unwrap(); + let mut reader = BufReader::new(fd); + let node = Node::read(&mut reader).unwrap(); + let FileType::HardLink(ref tgt) = node.filetype else { + eprintln!("Read incorrect filetype: {:?}", node.filetype); + panic!(); + }; + assert_eq!(tgt, "test/li.txt"); + } + #[test] fn extract_file() { let links = Mutex::new(HashMap::new());