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

Function collect

atomic-cli/src/commands/git/observation.rs:1587–1614  ·  view source on GitHub ↗
(root: &Path, current: &Path, values: &mut BTreeMap<PathBuf, SnapshotValue>)

Source from the content-addressed store, hash-verified

1585
1586 fn snapshot_tree(root: &Path) -> BTreeMap<PathBuf, SnapshotValue> {
1587 fn collect(root: &Path, current: &Path, values: &mut BTreeMap<PathBuf, SnapshotValue>) {
1588 let mut entries = fs::read_dir(current)
1589 .expect("read snapshot directory")
1590 .collect::<Result<Vec<_>, _>>()
1591 .expect("read snapshot entries");
1592 entries.sort_by_key(|entry| entry.file_name());
1593 for entry in entries {
1594 let path = entry.path();
1595 let relative = path.strip_prefix(root).expect("relative").to_path_buf();
1596 let file_type = entry.file_type().expect("file type");
1597 if file_type.is_symlink() {
1598 values.insert(
1599 relative,
1600 SnapshotValue::Symlink(fs::read_link(&path).expect("read link")),
1601 );
1602 } else if file_type.is_dir() {
1603 values.insert(relative, SnapshotValue::Directory);
1604 collect(root, &path, values);
1605 } else if file_type.is_file() {
1606 values.insert(
1607 relative,
1608 SnapshotValue::File(fs::read(&path).expect("read file")),
1609 );
1610 } else {
1611 values.insert(relative, SnapshotValue::Other);
1612 }
1613 }
1614 }
1615
1616 let mut values = BTreeMap::new();
1617 collect(root, root, &mut values);

Callers 2

snapshot_treeFunction · 0.70

Calls 7

is_dirMethod · 0.80
FileClass · 0.50
readFunction · 0.50
file_nameMethod · 0.45
pathMethod · 0.45
insertMethod · 0.45
is_fileMethod · 0.45

Tested by

no test coverage detected