Issue 17076: shutil.copytree failing on xattr-less filesystems (like NFS) (original) (raw)
The new xattr support in shutil causes shutil.copytree and shutil.copy2 to fail inelegantly on (source) filesystems that do not support xattrs (like NFS):
/home/twouters does not support xattrs
os.listxattr("/home/twouters/foo") Traceback (most recent call last): File "", line 1, in OSError: [Errno 95] Operation not supported: '/home/twouters/foo'
shutil.copytree("/home/twouters/spam", "/tmp/spam") Traceback (most recent call last): File "", line 1, in File "/home/twouters/gvs-pristine/python/Python-3.Lib/shutil.py", line 345, in copytree raise Error(errors) shutil.Error: [('/home/twouters/spam/ham', '/tmp/spam/ham', "[Errno 95] Operation not supported: '/home/twouters/spam/ham'"), ('/home/twouters/spam/eggs', '/tmp/spam/eggs', "[Errno 95] Operation not supported: '/home/twouters/spam/eggs'"), ('/home/twouters/spam', '/tmp/spam', "[Errno 95] Operation not supported: '/home/twouters/spam'")]
(The actual files will have been copied, since xattr copies are done after everything else.) Interestingly shutil._copyxattr does try to cope with unsupported xattrs on the target filesystem (which seems like it might be a mistake to do, since it loses data), just not the original filesystem (which seems like a sensible thing instead):
/tmp does support xattrs
os.listxattr("/tmp/spam") [] shutil.copytree("/tmp/spam", "/home/twouters/spam-new") '/home/twouters/spam-new'
The attached patch fixes shutil._copyxattr to also ignore unsupported/empty xattrs (but not permission errors) on the source. (I'm not certain if errno.ENODATA can be expected from os.listxattr(), but internet searches suggest that some people think so, and I don't know what other meaning it could have.)