Skip to content

Commit

Permalink
fix atomic file replace on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Aug 23, 2020
1 parent 2e0ee5f commit 79b098c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pre_commit/commands/install_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')


Expand Down
2 changes: 1 addition & 1 deletion pre_commit/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pre_commit/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, directory: Optional[str] = None) -> None:
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]:
Expand Down

0 comments on commit 79b098c

Please sign in to comment.