-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make ensure_path_nonexistent race condition aware #429
Make ensure_path_nonexistent race condition aware #429
Conversation
src/batou/lib/file.py
Outdated
path_basename = os.path.basename(os.path.normpath(path)) | ||
|
||
with tempfile.TemporaryDirectory(dir=parent_dir) as temp_dir: | ||
os.rename(path, os.path.join(temp_dir, path_basename)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can fail because the whole idea of a race condition means someone else might be doing unexpected stuff, so failing renames should be ignored if the path to delete is gone in any case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This context manager is for deleting the Temporary Directory. No assumption that os.rename may fail, but the happy path thankfully includes a deletion of the tmpdir
I can split it up if this is misleading
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rename needs to be wrapped in a try/except. Ignore for FileNotFound, re-raise in other cases.
…nt-race-condition-aware Make ensure_path_nonexistent race condition aware
This is susceptible to the same race conditions as the implementation from before, however it is able to notice the race condition and fail accordingly.
closes #275