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
shutil fails when copying to NTFS in Linux #45886
Comments
When using shutil.copy2 or copytree where the source is on a filesystem OSError: [Errno 1] Operation not permitted I am attaching a version of shutil.py where this has been worked around try: |
Better patch: import errno try: |
But is ok to hide the problem? I mean, there *is* an error: the operation is not permitted (even if |
I agree with Facundo that it is not good to hide the error. It should be |
This reminds me of an option in os.walk: """ We could do something similar, except that by default, errors are not |
I agree, the best would be to have the option of ignoring errors. |
os.walk has an error handling mechanism because it goes through a As this operation is applicable only to one file, this is not useful at Regarding the type of error, note that you can use the mechanism tiran In any case, this bug is not applicable any more. |
I must respectfully disagree. This bug also occurs during the copytree As far as working around it, it is obviously doable, however this Furthermore, I think that being able to ignore certain errors is very |
I'm -1 to the library ignore errors without specific indication from the We agree that copytree could grow an option like the one in os.walk. Thank you! |
There's already an except clause for copystat() that ignores |
The problem with WindowsError is that it is not included in Linux. So if >>> try: print a
... except WindowsError:
... print 'b'
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
NameError: name 'WindowsError' is not defined It should return "NameError: name 'a' is not defined" In my workaround, by placing the OSError before the WindowsError, this Let me see if I can figure out something a little better than always Thanks |
Hm, that means there's a bug in the existing copytree() code too! Can you check whether WindowsError derives from OSError? If it does, |
Yes, it is a sub-class of OSError. So then only catching OSError should |
Not quite, because we only want to ignore WindowsError. Maybe this would work? try: try: |
All the double negations are hurting when I try to understand above if WindowsError and isinstance(err, WindowsError):
pass # ignore
raise |
You're right, my code was wrong. Yours will be be correct if you add On Dec 3, 2007 2:25 PM, Raghuram Devarakonda <report@bugs.python.org> wrote:
|
Yeah. I was just about to correct my code when I saw your response. I |
Rather than try in copytree and try again in copy2, why not add this to def copystat(src, dst, ignore_permission_err=False):
"""Copy all stat info (mode bits, atime and mtime) from src to dst"""
st = os.stat(src)
mode = stat.S_IMODE(st.st_mode)
try:
if hasattr(os, 'utime'):
os.utime(dst, (st.st_atime, st.st_mtime))
if hasattr(os, 'chmod'):
os.chmod(dst, mode)
except OSError, err:
if WindowsError is not None and isinstance(err, WindowsError):
pass
elif ignore_permissions_err and err.errno == errno.EPERM:
pass
else:
raise |
Look at the except clause in copytree(); it does a bit more, |
OK I see that now. For what it's worth, I tested the code on win2000, I've made further modifications to allow for not showing permission Many thanks. |
sorry, should have clarified, I tested with this code: copy2 try: copytree try: |
The change looks fine as per yesterday's discussion. Can you submit |
Sure thing, here it is. |
hmm, marked me as spam ... the tar.gz posted last message contains the |
Some comments about shutil.diff:
Lastly, just to be clear, the original problem reported in this bug |
Sorry about that. Here is the output from $ svn diff I've also made modifications to allow to ignore the permission errors |
There is a mistake in the patch. The line "if WindowsError is not None |
I have submitted a patch (http://codereview.appspot.com/2384) for |
WindowsError issue is now fixed in r65644. |
I think this one is solved now. I recommend just to put as solved and kill it from the list ;) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: