Skip to content

Commit

Permalink
Prevent temp file deletion on file close on Windows. #121
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiocaccamo committed May 16, 2024
1 parent 94fb619 commit c5853f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions fsutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,7 @@ def _write_file_atomic(
mode=mode,
dir=dirpath,
delete=True,
delete_on_close=False,
encoding=encoding,
) as file:
file.write(content)
Expand Down
6 changes: 6 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,12 @@ def test_write_file_atomic(self):
fsutil.write_file(path, content="Hello Jupiter", atomic=True)
self.assertEqual(fsutil.read_file(path), "Hello Jupiter")

def test_write_file_atomic_no_temp_files_left(self):
path = self.temp_path("a/b/c.txt")
fsutil.write_file(path, content="Hello World", atomic=True)
fsutil.write_file(path, content="Hello Jupiter", atomic=True)
self.assertEqual(fsutil.list_files(self.temp_path("a/b/")), [path])

@unittest.skipIf(sys.platform.startswith("win"), "Test skipped on Windows")
def test_write_file_atomic_permissions_inheritance(self):
path = self.temp_path("a/b/c.txt")
Expand Down

0 comments on commit c5853f3

Please sign in to comment.