Skip to main content

Module util

Module util 

Source
Expand description

Small formatting/parsing helpers shared by the other modules.

Structs§

FileLock
Advisory exclusive lock on a file. Held for the lifetime of the value.

Constants§

GLYPH_FAIL
✕
GLYPH_INFO
◆
GLYPH_PASS
✓
GLYPH_WARN
▲

Functions§

check_regular_chain
Check that base/rel is a chain of real directories ending in a regular file, with no symlink at any component. Read-only; used before hashing or restoring a store file.
command_for
A Command for a trusted tool (cargo, rustc) or a user program: relative names are resolved through tool_path to an absolute path.
copy_file_hashed
Copy a regular file into a new destination (O_EXCL) while hashing it. Refuses symlinks/FIFOs/devices and never follows a destination symlink. Returns (bytes, sha256).
copy_file_verified
Copy + verify a recorded size/hash. On mismatch the new destination is removed and the operation fails (never installs unverified bytes).
create_dir_chain_nofollow
Create a directory chain under an existing base without following any symlink component. rel must already have been validated (only normal components). New components are 0700.
create_private_dir_all
Create a directory tree with mode 0700 (Unix), refusing a symlinked or foreign-owned final directory. Existing directories are tightened to 0700.
dim
Dimmed — labels, legends, secondary detail.
ensure_private_dir
Verify (and, when possible, repair) an existing private directory.
error_block
One failure rendered in the tool’s visual language: a red ✕ line, the message’s own continuation lines indented beneath it, then any anyhow causes as dim rows. Plain glyphs when colors are off.
euid
Effective uid. Only meaningful on Unix; 0 elsewhere (permission checks are skipped there and documented as such).
fail
Red — failures.
force_remove_dir
Remove a tree robustly: read-only files (a wrapper’s store, copies that inherited the read-only attribute) block remove_dir_all on Windows, so clear the flag and retry once; report the original error if it still fails.
green
Brand-green text (#92D293) — section titles and success accents.
heading
Bold brand green — top-level headings.
human_age
Age of a timestamp, human-readable (“3.4 days”).
human_bytes
1234567 -> "1.2 MiB" style, compact.
human_duration
Compact duration for humans (“3.4 s”, “1.2 min”, “2.1 h”).
info
Calm blue — neutral info.
on_path
Is program reachable through PATH? (bare which, no extra crate)
owned_by_us
Is this file owned by the current effective user? (always true off Unix)
parse_duration
Parse "30d", "2w", "12h", "90m", "45s" or plain seconds "45".
read_small_text
Read a small regular file without following a symlink and without blocking on FIFOs/devices. Returns an error on non-regular or oversized inputs.
read_small_text_follow
Like read_small_text but follows a user’s config symlink (dotfiles); still refuses FIFOs/devices and oversized inputs.
sha256_file
SHA-256 of a regular file (lowercase hex). Callers that accept untrusted paths must reject symlinks with symlink_metadata first.
tool_path
Resolve an executable to an absolute path. This is the Windows CWD-search fix: Command::new("cargo") must never be used directly.
validate_component
One path component: no separators, no ./.., no NUL, no Windows drive/ADS separator. Use for manifest fields that must be one directory or file name (name, profile, memo, parity keys).
validate_rel
A relative path with only normal components. Rejects absolute paths, .., ., NUL, drive prefixes, and backslash/forward-slash tricks. This is the single gate for every manifest path that reaches the filesystem.
warn
Amber — warnings.
which
Is program installed at all (PATH or cargo bin dir)?
which_path
Absolute path of program if discoverable — first on PATH, then as a fallback in Cargo’s own bin dir ($CARGO_HOME/bin, e.g. C:\Users\<user>\.cargo\bin), which rustup tools live in but isn’t on PATH in every shell. Returns None when not found anywhere.