mirror of
https://github.com/tobi/disktree.git
synced 2026-11-28 08:00:53 +00:00
Keep a snapshot-booted root's subvolumes, and stat directories on macOS
The projection from #56 tested the scanned mount for being a snapshot as well as the other one. On a system booted from a Snapper snapshot, as openSUSE is by default, `/` is one, so every mark under `/var` or `/home` was called another volume's although the scan walks them as its own. Only the other mount is tested now, as `foreign_mounts` does. The bulk listing from #53 is thought to report a mount point with the attributes of the directory it covers, so its device would be the parent volume's and the walk would cross into every disk, share and system volume below the root. Directories are stated with `statat` again, as `lstat` did before; files keep the bulk path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
536f037e0f
commit
fcb627634f
@@ -460,9 +460,13 @@ impl<'a> Cursor<'a> {
|
||||
self.at += 8;
|
||||
let flags = self.u32()?;
|
||||
let inode = self.u64()?;
|
||||
// A directory's own size is never measured; its entries are.
|
||||
// A directory is stated the ordinary way. A mount point is listed
|
||||
// with the attributes of the directory it covers, so its DEVID is
|
||||
// the parent volume's, and the walk would cross into every disk,
|
||||
// share and system volume mounted below the root. `statat` reads
|
||||
// the mounted root, as `lstat` did; directories are few beside files.
|
||||
let (links, allocated, apparent) = if kind == Kind::Directory {
|
||||
(1, 0, 0)
|
||||
return Ok(None);
|
||||
} else if file & FILE_ATTRIBUTES == FILE_ATTRIBUTES {
|
||||
(self.u32()?, self.u64()?, self.u64()?)
|
||||
} else {
|
||||
|
||||
@@ -269,14 +269,16 @@ fn covering<'a>(mounts: &'a [Mount], path: &Path) -> Option<&'a Mount> {
|
||||
/// source: its files share their blocks with the live ones, so removing them
|
||||
/// gives back almost nothing, and the scan keeps out of it for the same
|
||||
/// reason. The mount the scan itself asked for is kept at all events, since
|
||||
/// removing something there empties the very space the meter reads.
|
||||
/// removing something there empties the very space the meter reads. Only
|
||||
/// the other mount is tested, as [`foreign_mounts`] does: a system booted
|
||||
/// from a snapshot (openSUSE's Snapper default) has one at `/`, and its
|
||||
/// `/var` and `/home` are still the scan's own.
|
||||
fn same_volume(own: &Mount, other: &Mount) -> bool {
|
||||
if own.point == other.point {
|
||||
return true;
|
||||
}
|
||||
own.source == other.source
|
||||
&& own.fstype == other.fstype
|
||||
&& !is_snapshot(own)
|
||||
&& !is_snapshot(other)
|
||||
}
|
||||
|
||||
@@ -1133,6 +1135,25 @@ portal /run/user/1000/doc fuse.portal rw 0 0
|
||||
);
|
||||
}
|
||||
|
||||
/// openSUSE boots from a Snapper snapshot, so `/` itself is one; the
|
||||
/// scan still walks `/var` and `/home`, and so does the projection.
|
||||
#[test]
|
||||
fn a_root_booted_from_a_snapshot_keeps_its_subvolumes() {
|
||||
let mounts = parse_mounts(
|
||||
"/dev/vda2 / btrfs rw,subvol=/@/.snapshots/1/snapshot 0 0\n\
|
||||
/dev/vda2 /var btrfs rw,subvol=/@/var 0 0\n\
|
||||
/dev/vda2 /home btrfs rw,subvol=/@/home 0 0\n",
|
||||
);
|
||||
assert!(foreign_mounts(&mounts, Path::new("/")).is_empty());
|
||||
for path in ["/var/cache/x", "/home/me/x", "/usr/x"] {
|
||||
assert_eq!(
|
||||
attribution(Some(&mounts), Path::new("/"), Path::new(path)),
|
||||
Attribution::Scanned,
|
||||
"{path}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_table_that_does_not_place_a_path_claims_nothing() {
|
||||
let partial = parse_mounts("/dev/sdb1 /data ext4 rw 0 0\n");
|
||||
|
||||
Reference in New Issue
Block a user