-
Notifications
You must be signed in to change notification settings - Fork 530
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
[FIX] Also allow errno.EBUSY
during emptydirs
on NFS
#3357
Conversation
Might need to merge/rebase master to fix the dipy issue. |
- Can occur if a file is still open somewhere, so NFS will rename it to a hidden file in the same directory - When `shutil` tries to delete that hidden file, we get an `OSError` with `errno.EBUSY`
- I forgot that `os.listdir` also lists hidden files in the previous commit
- With mock for NFS silly-rename (yes, it's really called that) behavior
52d6e34
to
6fec48b
Compare
I just noticed that I had this error, because I had another instance of the workflow open in a different terminal, still open in the debugger. Closing that instance of Python solved the issue. As a result, I think the issue I had comes down to user error. Nevertheless, it's probably still nice to keep this code, I can imagine other cases of people opening and keeping open files while the workflow is still running (like inspecting an image). |
Codecov Report
@@ Coverage Diff @@
## master #3357 +/- ##
=======================================
Coverage 65.11% 65.12%
=======================================
Files 307 307
Lines 40373 40373
Branches 5326 5327 +1
=======================================
+ Hits 26288 26291 +3
+ Misses 13014 13010 -4
- Partials 1071 1072 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
I wanted to try commiting like this, let's see if it works :-)
Handle mock test case when no `dir_fd` is passed
if dir_fd is None: | ||
path = Path(pathlike) | ||
deleted = path.with_name(".nfs00000000") | ||
path.rename(deleted) | ||
else: | ||
os.rename(pathlike, ".nfs1111111111", src_dir_fd=dir_fd, dst_dir_fd=dir_fd) |
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.
I do like your idea of avoiding branching. What if we just construct the target correctly?
if dir_fd is None: | |
path = Path(pathlike) | |
deleted = path.with_name(".nfs00000000") | |
path.rename(deleted) | |
else: | |
os.rename(pathlike, ".nfs1111111111", src_dir_fd=dir_fd, dst_dir_fd=dir_fd) | |
target = os.path.join(os.path.dirname(pathlike), ".nfs00000000") | |
os.rename(pathlike, target, src_dir_fd=dir_fd, dst_dir_fd=dir_fd) |
Demo:
>>> [os.path.join(os.path.dirname(pathlike), ".nfs00000000")
... for pathlike in ["path/subdir/busyfile", "busyfile"]]
['path/subdir/.nfs00000000', '.nfs00000000']
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.
Green check in any case. Happy to merge as-is, or if you want to make that change.
Summary
Running a workflow with nipype 1.6.1, I sometimes get the following exception:
As far as I can tell, if a file on an NFS mount is still open somewhere, when it is deleted, NFS will rename that file to a hidden file ("placeholder") in the same directory so that the data stays available to the open file handle (according to https://unix.stackexchange.com/a/348678). When
shutil
discovers that hidden file, it will try to delete it, and we get anOSError
witherrno.EBUSY
List of changes proposed in this PR (pull-request)
errno.ENOTEMPTY
, which is already handled by current codeAcknowledgment