(root: &Path)
| 58 | } |
| 59 | |
| 60 | fn snapshot_tree(root: &Path) -> BTreeMap<PathBuf, SnapshotValue> { |
| 61 | fn collect(root: &Path, current: &Path, values: &mut BTreeMap<PathBuf, SnapshotValue>) { |
| 62 | let mut entries = fs::read_dir(current) |
| 63 | .expect("read snapshot directory") |
| 64 | .collect::<Result<Vec<_>, _>>() |
| 65 | .expect("read snapshot entries"); |
| 66 | entries.sort_by_key(|entry| entry.file_name()); |
| 67 | for entry in entries { |
| 68 | let path = entry.path(); |
| 69 | let relative = path |
| 70 | .strip_prefix(root) |
| 71 | .expect("relative path") |
| 72 | .to_path_buf(); |
| 73 | let file_type = entry.file_type().expect("file type"); |
| 74 | if file_type.is_symlink() { |
| 75 | values.insert( |
| 76 | relative, |
| 77 | SnapshotValue::Symlink(fs::read_link(&path).expect("read symlink")), |
| 78 | ); |
| 79 | } else if file_type.is_dir() { |
| 80 | values.insert(relative, SnapshotValue::Directory); |
| 81 | collect(root, &path, values); |
| 82 | } else if file_type.is_file() { |
| 83 | values.insert( |
| 84 | relative, |
| 85 | SnapshotValue::File(fs::read(&path).expect("read file")), |
| 86 | ); |
| 87 | } else { |
| 88 | values.insert(relative, SnapshotValue::Other); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | let mut values = BTreeMap::new(); |
| 94 | collect(root, root, &mut values); |
| 95 | values |
| 96 | } |
| 97 | |
| 98 | #[test] |
| 99 | fn no_reconcile_reports_forensics_without_mutating_git_or_atomic() { |
no test coverage detected