Skip to content

Commit 79b098c

Browse files
committed
fix atomic file replace on windows
1 parent 2e0ee5f commit 79b098c

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

pre_commit/commands/install_uninstall.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def _uninstall_hook_script(hook_type: str) -> None:
165165
output.write_line(f'{hook_type} uninstalled')
166166

167167
if os.path.exists(legacy_path):
168-
os.rename(legacy_path, hook_path)
168+
os.replace(legacy_path, hook_path)
169169
output.write_line(f'Restored previous hooks to {hook_path}')
170170

171171

pre_commit/repository.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def _write_state(prefix: Prefix, venv: str, state: object) -> None:
4848
with open(staging, 'w') as state_file:
4949
state_file.write(json.dumps(state))
5050
# Move the file into place atomically to indicate we've installed
51-
os.rename(staging, state_filename)
51+
os.replace(staging, state_filename)
5252

5353

5454
def _hook_installed(hook: Hook) -> bool:

pre_commit/store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def __init__(self, directory: Optional[str] = None) -> None:
7979
self._create_config_table(db)
8080

8181
# Atomic file move
82-
os.rename(tmpfile, self.db_path)
82+
os.replace(tmpfile, self.db_path)
8383

8484
@contextlib.contextmanager
8585
def exclusive_lock(self) -> Generator[None, None, None]:

0 commit comments

Comments
 (0)