fs
fs
¶
Filesystem helpers for directory creation, writability checks, and config and secret files.
__all__ = ['ensure_dir', 'ensure_dir_writable', 'write_config_file', 'write_sensitive_file']
module-attribute
¶
ensure_dir(path, *, mode=511)
¶
Create missing directories with mode, subject to the process umask.
New directories use the account's primary group when possible, not a
transient newgrp group that rootless Podman may not map. Explicit
setgid inheritance takes precedence. Existing directories keep their
ownership, permissions and ACLs.
Source code in src/terok_util/fs.py
ensure_dir_writable(path, label, *, private=False)
¶
Create path if needed and verify it is writable, or exit with an error.
With private, the directories this creates get mode 0o700;
directories that exist already keep theirs.
Source code in src/terok_util/fs.py
write_config_file(path, text)
¶
Write text to the operator-owned config file at path.
An existing file is rewritten in place, so what the operator set up
stays: a symlink still points where it did, and the file keeps its
mode and owner. A new file is created with mode 0o600, and the
directories created for it with 0o700, so config is private by
default.
Source code in src/terok_util/fs.py
write_sensitive_file(path, content)
¶
Atomically create path with mode 0o600 and write content.
Returns True if the file was created, False if it already existed.
Missing parent directories are created with mode 0o700. Existing
parents keep their ownership, permissions and ACLs.
Refuses to operate if path.parent is a symbolic link.
Opens the file with O_NOFOLLOW
so a planted symlink at the final path cannot redirect the write.