Skip to main content

Module attrs

Module attrs 

Source
Expand description

Where a new file’s POSIX mode / uid / gid actually come from.

Every Unix filesystem we can edit — ext, UFS, XFS, EFS, Minix, and SquashFS once its edit path lands — already honours CreateFileOptions’s mode, uid and gid. Until now nothing set them: rb-cli put left all three at None, so each driver fell back to its own unwrap_or and every added file silently became root:root 0644.

That is defensible as a last resort and wrong as a default. Replacing /etc/shadow should not turn it world-readable; dropping a script into /usr/local/bin should not make it non-executable; and replacing a capability-bearing binary should not quietly strip its ownership.

This module is the one place that decides, so the CLI, GUI and TUI cannot drift. The rule, highest priority first:

AttributePrecedence
modeexplicit flag -> file being replaced -> host file’s own bits -> fallback
uidexplicit flag -> file being replaced -> parent directory -> 0
gidexplicit flag -> file being replaced -> parent directory -> 0

Replacing an existing file inherits from it, because that is the common edit — swap a config, replace a binary — and the file already carries the answer. A genuinely new file takes ownership from its parent directory, which is how the surrounding tree is almost always laid out. The host file’s permission bits are consulted for mode only: macOS carries those faithfully, but its uid/gid (typically 501:20) are meaningless inside a Linux image.

Each resolved value records where it came from so the operation can say so rather than guessing silently — see ResolvedAttrs::describe.

Structs§

AttrOverrides
Caller-supplied overrides. None means “decide for me”.
PreservedMeta
Everything worth carrying from a file that is about to be replaced.
ResolvedAttrs
The decision, with provenance per field.

Enums§

AttrSource
Which input supplied a resolved attribute.

Functions§

add_execute_where_read
Add execute wherever read is already granted — exactly chmod a+X.
inherited_xattrs
The extended attributes a replacement file should inherit from the file it displaces.
preserved_meta
Capture the metadata of a file about to be replaced.
resolve_attrs
Resolve the POSIX attributes for a file about to be created.
resolve_dir_attrs
Resolve the POSIX attributes for a directory about to be created.