| 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); |