MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / snapshot_tree

Function snapshot_tree

atomic-cli/tests/it/git_push_cb4b_test.rs:62–98  ·  view source on GitHub ↗
(root: &Path)

Source from the content-addressed store, hash-verified

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

Calls 1

collectFunction · 0.70

Tested by

no test coverage detected