fs
fs
¶
Filesystem helpers for directory creation and writability checks.
__all__ = ['ensure_dir', 'ensure_dir_writable', 'write_sensitive_file']
module-attribute
¶
ensure_dir(path)
¶
ensure_dir_writable(path, label)
¶
Create path if needed and verify it is writable, or exit with an error.
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.
Parent directories are created with mode 0o700.
Refuses to operate if path.parent is a symbolic link — chmod would
otherwise follow the link target. Opens the file with O_NOFOLLOW
so a planted symlink at the final path cannot redirect the write.