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.

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

13461346 append: bool = False,
13471347 encoding: str = "utf-8",
13481348 ) -> None:
1349+ path = _get_path(path)
13491350 mode = "a" if append else "w"
13501351 if append:
13511352 content = read_file(path, encoding=encoding) + content
13601361 file.write(content)
13611362 file.flush()
13621363 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)
13641368 except FileNotFoundError:
13651369 # success - the NamedTemporaryFile has not been able
13661370 # to remove the temp file on __exit__ because the temp file

The check that tells the two apart

failpass·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