a generation's file already linked to the active one's copy is left alone, instead of leaving its share link behind
Signed-off-by: dawn <dawn@klbr.net>
157 unmodified linesExpand all158159160161162163162163164165166167168169170171172173174241 unmodified linesExpand all416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445157 unmodified linesExpand all } let path = entry.path(); let relative = path.strip_prefix(root).expect("below the root"); let theirs = active.join(relative); let len = entry.metadata()?.len(); let same = kind.is_file() let meta = entry.metadata()?; let len = meta.len(); // renaming a link over another link to the same file does nothing, and leaves it let linked = std::fs::symlink_metadata(&theirs).is_ok_and(|theirs| { use std::os::unix::fs::MetadataExt as _; (theirs.dev(), theirs.ino()) == (meta.dev(), meta.ino()) }); let same = !linked && kind.is_file() && std::fs::symlink_metadata(&theirs) .is_ok_and(|meta| meta.is_file() && meta.len() == len) && std::fs::read(&theirs)? == std::fs::read(&path)?; if same {241 unmodified linesExpand all } } total}
#[cfg(test)]mod tests { use std::os::unix::fs::MetadataExt as _;
#[test] fn a_file_already_linked_to_the_active_ones_is_left_as_it_is() { let dir = tempfile::tempdir().unwrap(); let (root, active) = (dir.path().join("new"), dir.path().join("active")); crate::cas::atomic_write(&active.join("www/og/card.png"), b"card").unwrap(); crate::cas::atomic_write(&active.join("www/same"), b"same").unwrap(); crate::cas::atomic_write(&root.join("www/same"), b"same").unwrap(); std::fs::create_dir_all(root.join("www/og")).unwrap(); std::fs::hard_link(active.join("www/og/card.png"), root.join("www/og/card.png")).unwrap();
super::share_unchanged(&root, &active).unwrap();
let og: Vec<_> = std::fs::read_dir(root.join("www/og")) .unwrap() .map(|entry| entry.unwrap().file_name()) .collect(); assert_eq!(og, ["card.png"]); let ino = |path: std::path::PathBuf| std::fs::metadata(path).unwrap().ino(); assert_eq!(ino(root.join("www/same")), ino(active.join("www/same"))); }}