pub fn ensure_writable_tree(root: &Path) -> Result<WritableReport>Expand description
Ensure every entry under root (inclusive) is owner-writable, so later
cache operations (attribute changes, rotation, deletion) never fail on
read-only modes inherited from release archives.
Call it once, right after extracting an archive into its final cache
location. It fixes the observed failure where 0444 files from release
tarballs made post-extract steps (e.g. macOS xattr -dr quarantine
strips, Windows tree deletion on rotation) fail with permission errors.
There is deliberately no staging concept in this crate: validity of a
cached tree is the presence of the caller’s sentinel file, so a killed
fetch leaves a sentinel-less tree the next run simply refetches.
Semantics, by platform:
- Unix: sets the owner-write bit (
0o200), preserving every other mode bit. Never broadens group/other access. - Windows (and other non-Unix): clears the readonly flag. This is the
portable
set_readonly(false)behavior.
Security contract:
- Symlinks are never followed and never modified (a malicious archive
cannot redirect the walk outside
root, and link targets keep their modes). - Traversal stays under
root: recursion only descends into directories reached viaread_dirfromroot. - Deterministic order (sorted entries), so repeated runs behave identically.
- Fail-closed: the first I/O error aborts with the offending path in the message.
Returns counts of fixed entries; a second run over the same tree reports zeros.