zabgrab.adapters.files¶
Helpers for writing files safely.
Functions
|
Give a temporary file the permissions |
|
Write a file via a temporary file, so it's never left half-written. |
- zabgrab.adapters.files.replacing(path, *, copy=False)[source]¶
Write a file via a temporary file, so it’s never left half-written.
The temporary file is created next to
path(so replacing it is atomic) and replacespathwhen thewithblock ends without an error. If it fails, the temporary file is deleted andpathis left as it was.- Parameters:
path (Path) – The file to write. Its directory is created if needed.
copy (bool, optional) – Start the temporary file as a copy of
path, to change it rather than write it from scratch.
- Yields:
Path – The temporary file to write to.
- Raises:
OSError – If the file can’t be written.
- Return type:
- zabgrab.adapters.files.match_permissions(temporary, path)[source]¶
Give a temporary file the permissions
pathshould end up with.Temporary files are private (0600). When one replaces
path, it should keeppath’s permissions, or get the usual ones for new files (from the umask).- Parameters:
temporary (Path) – The temporary file, about to replace
path.path (Path) – The file being written (which may not exist yet).
- Return type:
None