Merge pull request #1577 from pre-commit/os_replace

fix atomic file replace on windows
This commit is contained in:
Anthony Sottile
2020-08-23 10:49:14 -07:00
committed by GitHub
3 changed files with 3 additions and 3 deletions

View File

@@ -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}')

View File

@@ -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:

View File

@@ -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]: