Whole file
fabiocaccamo/python-fsutil
The author described this change as “Fix permissions lost when using `write_file` with `atomic=True`. #94”. It counts as a record because the check below fails on the code as it stood at 6bf89c87e and passes on 5c14e6f3a, with nothing else changed between the two runs.
Projectfabiocaccamo/python-fsutil
Fix saved2023-12-19
Sharing licenceMIT · LICENSE.txt
Change size+5 −1
What the code was meant to do, written into the code itself as a save note
Fix permissions lost when using `write_file` with `atomic=True`. #94
The change
| 1346 | 1346 | append: bool = False, | |
| 1347 | 1347 | encoding: str = "utf-8", | |
| 1348 | 1348 | ) -> None: | |
| 1349 | + | path = _get_path(path) | |
| 1349 | 1350 | mode = "a" if append else "w" | |
| 1350 | 1351 | if append: | |
| 1351 | 1352 | content = read_file(path, encoding=encoding) + content | |
| ⋯ | |||
| 1360 | 1361 | file.write(content) | |
| 1361 | 1362 | file.flush() | |
| 1362 | 1363 | os.fsync(file.fileno()) | |
| 1363 | - | os.replace(file.name, path) | |
| 1364 | + | temp_path = file.name | |
| 1365 | + | if exists(path): | |
| 1366 | + | set_permissions(temp_path, get_permissions(path)) | |
| 1367 | + | os.replace(temp_path, path) | |
| 1364 | 1368 | except FileNotFoundError: | |
| 1365 | 1369 | # success - the NamedTemporaryFile has not been able | |
| 1366 | 1370 | # to remove the temp file on __exit__ because the temp file | |
The check that tells the two apart
fail→pass·tests/test.py::fsutil_test_case::test_write_file_atomic_permissions_inheritance
Check file tests/test.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it6bf89c87e2acc223c74be11b056886121599ab35
Broken version dated2023-12-19
Modulefsutil.__init__
Units changed_write_file_atomic
Fingerprinta5577242aed2c669
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in fabiocaccamo/python-fsutil
- 2026-07-07convert_size_bytes_to_string
- 2026-04-07_search_paths
- 2024-05-16join_path
- 2023-01-11make_dirs_for_file