Skip to main content

Module walk

Module walk 

Source
Expand description

In-process filesystem walk producing a frozen-format Manifest.

This module reproduces the original snapdir-manifest generate behavior in pure Rust, consuming the frozen manifest, merkle and excludes APIs without changing any of them. It walks a directory tree and emits one ManifestEntry per file (F) and directory (D), computing per-file content checksums with a Hasher and per-directory checksums/sizes with [directory_checksum].

§Behaviors matched against the oracle

  • Traversal mirrors find/find -L: every directory becomes a D entry (path ending /) and every regular file directly inside it becomes an F entry. Directories are recorded even when empty.
  • Symlinks are followed by default (FollowMode::Follow, the oracle’s find -L): a symlink to a directory is reported as a directory and descended into, a symlink to a file as a file, inheriting the target’s type/permissions/size/checksum. FollowMode::NoFollow (plain find) drops symlinks entirely — they appear as neither D nor F.
  • Permissions are the octal mode bits, matching stat -f '%A' (macOS) / stat -c '%a' (Linux): the low 12 bits of st_mode rendered in octal with no leading zero (e.g. 755, 644, 700).
  • File size is the content byte length (%z / %s). Directory size is the sum of its direct members’ sizes (files and subdirectories), excluding the directory’s own stat size — matching the oracle’s _snapdir_manifest_sum_lines over the direct children.
  • Excludes are applied via ExcludeMatcher against the absolute path of each candidate directory and file, mirroring the oracle’s find … | grep -E -v "$EXCLUDE" (the filter runs before the relative ./ rewrite). A %system% expansion forces FollowMode::NoFollow; the caller resolves that via expand_excludes.
  • Paths are absolute under PathMode::Absolute, or rewritten to a leading ./ under PathMode::Relative (the oracle’s sed -E "s| \.?${root_dir}| .|"). Directory paths always end with /.
  • Ordering is sort -k5 (byte-wise on the path), delegated to Manifest’s own sort.

Per the library-purity principle this module reads the filesystem at the given root path (that is its job) but reads no $HOME/config/environment for behavior: the root, options, excludes and hasher all arrive as parameters, and errors surface as the typed WalkError.

Structs§

WalkOptions
Options controlling a walk.

Enums§

PathMode
Whether emitted paths are absolute or rewritten relative to the root.
WalkError
Errors raised while walking the filesystem.

Functions§

walk
Walks the directory tree rooted at root, producing a Manifest that matches the original snapdir-manifest output byte-for-byte for the same tree and checksum function.
walk_with_meter
Like walk, but records hashing progress into an optional Meter.