From ff1afa64536f9e05ff635b4892d20491bf73780e Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Mon, 11 Dec 2023 19:29:29 -0500 Subject: [PATCH] Add test for creating symlink nodes and fix code to pass test --- src/node.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/node.rs b/src/node.rs index ef0ffae..69c96cb 100644 --- a/src/node.rs +++ b/src/node.rs @@ -132,7 +132,7 @@ impl Node { ) -> Result { let name = String::from(path); let fd = fs::File::open(path)?; - let meta = fd.metadata()?; + let meta = fs::symlink_metadata(path)?; let mode = meta.mode(); let uid = meta.uid(); let gid = meta.gid(); @@ -310,12 +310,12 @@ impl Node { #[cfg(test)] mod tests { use super::*; - use std::fmt::Write; + use std::{fmt::Write, fs::remove_file}; static LI: &[u8] = include_bytes!("../test/li.txt"); #[test] - fn from_path() { + fn from_file_path() { let links = Mutex::new(HashMap::new()); let node = Node::from_path("test/li.txt", Algorithm::Sha256, &links).unwrap(); let FileType::Normal(f) = node.filetype else { @@ -336,7 +336,20 @@ mod tests { } #[test] - fn load_store() { + fn from_symlink_path() { + let _res = remove_file("test/lilnk.txt"); + symlink("li.txt", "test/lilnk.txt").unwrap(); + let links = Mutex::new(HashMap::new()); + let node = Node::from_path("test/lilnk.txt", Algorithm::Skip, &links).unwrap(); + let FileType::SoftLink(tgt) = node.filetype else { + eprintln!("Incorrect filetype: {:?}", node.filetype); + panic!(); + }; + assert_eq!(tgt, "li.txt"); + } + + #[test] + fn load_store_file() { { let fd = std::fs::File::create("test/li.node").unwrap(); let mut writer = std::io::BufWriter::new(fd);