-
Notifications
You must be signed in to change notification settings - Fork 202
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
implement workaround for permission error when copying read-only files that have extended attributes set and using Python 3.6 #4642
Conversation
I think this is the real problem that I thought I was solving with #4604 |
Co-authored-by: ocaisa <[email protected]>
To me this now looks good, but can we add a test for it? It may not be very thorough, but you should just be able to create a file, change the permissions to read-only and then attempt a copy. I don't know if that is guaranteed to hit the LoC, but it is worth a shot. Should be a variation on easybuild-framework/test/framework/filetools.py Lines 1805 to 1810 in f7035e9
|
I have traced the underlying issue to: https://bugs.python.org/issue24538 So this should only appear in python < 3.7 |
since the |
Like everything, this was more work than it seemed initially! |
@ocaisa I've pushed another commit (or two) that actually use the upstream approach to ensure the extended attributes are truly copied as well. A cleaner fix imo |
# re-enable user write permissions in target, copy xattrs, then remove write perms again | ||
adjust_permissions(target_path, stat.S_IWUSR) | ||
shutil._copyxattr(path, target_path) | ||
adjust_permissions(target_path, stat.S_IWUSR, add=False) |
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.
Ha, this is correct but quite confusing (add=False
means remove the permissions)
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.
yeah, hence the comment at the top of that block
it's not the most intuitive that add=False
removes the permissions
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.
Should we open an issue to improve the API of adjust_permissions
in EasyBuild 5.0?
There really should be a dedicated test that verifies whether the changes indeed fix the problem at hand. I puzzled one together, see jfgrimm#1 Unless I'm misunderstanding something, the extra test shows the fix isn't fully working as designed yet, since it fails on Python 3.6.8 in RHEL8... |
easybuild/tools/filetools.py
Outdated
if not os.stat(path).st_mode & stat.S_IWUSR: | ||
# failure not due to read-only file | ||
raise EasyBuildError("Failed to copy file %s to %s: %s", path, target_path, err) |
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 part doesn't make sense to me, I think it should be removed...
If we give up here if the source file is read-only, then why bother with the attempt to fix the issue when using Python 3.6 via shutil._copyxattr
below?
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.
implement test for `copy_file` to copy read-only file with extended attributes
Ran into this issue like this, when configuring EasyBuild with read-only-installdir:
Having taken a closer look, it seems that on our system
shutil.copy2()
spits out aPermissionError
when the file to be copied is read-only. However, the copy still succeeds (and has the correct contents).