Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(69455)

Unified Diff: Lib/shutil.py

Issue 15238: shutil.copystat should copy Linux extended attributes
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Doc/library/shutil.rst ('k') | Lib/test/test_shutil.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/shutil.py Sun Jul 01 12:24:20 2012 +0200
+++ b/Lib/shutil.py Tue Jul 03 09:05:12 2012 +0200
@@ -132,6 +132,27 @@
st = stat_func(src)
chmod_func(dst, stat.S_IMODE(st.st_mode))
+if hasattr(os, 'listxattr'):
+ def _copyxattr(src, dst, symlinks=False):
+ """Copy extended filesystem attributes from `src` to `dst`.
+
+ Overwrite existing attributes.
+
+ If the optional flag `symlinks` is set, symlinks won't be followed.
+
+ """
+
+ for name in os.listxattr(src, follow_symlinks=symlinks):
+ try:
+ value = os.getxattr(src, name, follow_symlinks=symlinks)
+ os.setxattr(dst, name, value, follow_symlinks=symlinks)
+ except OSError as e:
+ if e.errno not in (errno.EPERM, errno.ENOTSUP, errno.ENODATA):
+ raise
+else:
+ def _copyxattr(*args, **kwargs):
+ pass
+
def copystat(src, dst, symlinks=False):
"""Copy all stat info (mode bits, atime, mtime, flags) from src to dst.
@@ -184,27 +205,7 @@
break
else:
raise
-
-if hasattr(os, 'listxattr'):
- def _copyxattr(src, dst, symlinks=False):
- """Copy extended filesystem attributes from `src` to `dst`.
-
- Overwrite existing attributes.
-
- If the optional flag `symlinks` is set, symlinks won't be followed.
-
- """
-
- for name in os.listxattr(src, follow_symlinks=symlinks):
- try:
- value = os.getxattr(src, name, follow_symlinks=symlinks)
- os.setxattr(dst, name, value, follow_symlinks=symlinks)
- except OSError as e:
- if e.errno not in (errno.EPERM, errno.ENOTSUP, errno.ENODATA):
- raise
-else:
- def _copyxattr(*args, **kwargs):
- pass
+ _copyxattr(src, dst, symlinks=follow)
def copy(src, dst, symlinks=False):
"""Copy data and mode bits ("cp src dst"). Return the file's destination.
@@ -235,7 +236,6 @@
dst = os.path.join(dst, os.path.basename(src))
copyfile(src, dst, symlinks=symlinks)
copystat(src, dst, symlinks=symlinks)
- _copyxattr(src, dst, symlinks=symlinks)
return dst
def ignore_patterns(*patterns):
« no previous file with comments | « Doc/library/shutil.rst ('k') | Lib/test/test_shutil.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+