mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-18 06:55:25 -06:00
Merge pull request #1577 from pre-commit/os_replace
fix atomic file replace on windows
This commit is contained in:
@@ -165,7 +165,7 @@ def _uninstall_hook_script(hook_type: str) -> None:
|
||||
output.write_line(f'{hook_type} uninstalled')
|
||||
|
||||
if os.path.exists(legacy_path):
|
||||
os.rename(legacy_path, hook_path)
|
||||
os.replace(legacy_path, hook_path)
|
||||
output.write_line(f'Restored previous hooks to {hook_path}')
|
||||
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ def _write_state(prefix: Prefix, venv: str, state: object) -> None:
|
||||
with open(staging, 'w') as state_file:
|
||||
state_file.write(json.dumps(state))
|
||||
# Move the file into place atomically to indicate we've installed
|
||||
os.rename(staging, state_filename)
|
||||
os.replace(staging, state_filename)
|
||||
|
||||
|
||||
def _hook_installed(hook: Hook) -> bool:
|
||||
|
||||
@@ -79,7 +79,7 @@ class Store:
|
||||
self._create_config_table(db)
|
||||
|
||||
# Atomic file move
|
||||
os.rename(tmpfile, self.db_path)
|
||||
os.replace(tmpfile, self.db_path)
|
||||
|
||||
@contextlib.contextmanager
|
||||
def exclusive_lock(self) -> Generator[None, None, None]:
|
||||
|
||||
Reference in New Issue
Block a user