summaryrefslogtreecommitdiffstats
path: root/pym/portage/util/movefile.py
diff options
context:
space:
mode:
authorArfrever Frehtes Taifersar Arahesis <Arfrever@Gentoo.Org>2011-11-29 02:26:04 +0100
committerArfrever Frehtes Taifersar Arahesis <Arfrever@Gentoo.Org>2011-11-29 02:26:04 +0100
commitddc9dbc832b3424da722f7442cf33327423735a6 (patch)
treeac58a9fe5c970ed8adb459c5e22fdb27a30ac645 /pym/portage/util/movefile.py
parent7c5b170d47ab054bc3f8a7778dd3f8139c1239c6 (diff)
downloadportage-ddc9dbc832b3424da722f7442cf33327423735a6.tar.gz
portage-ddc9dbc832b3424da722f7442cf33327423735a6.tar.bz2
portage-ddc9dbc832b3424da722f7442cf33327423735a6.zip
Preserve extended attributes on regular files when using Python >=3.3.
Diffstat (limited to 'pym/portage/util/movefile.py')
-rw-r--r--pym/portage/util/movefile.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/pym/portage/util/movefile.py b/pym/portage/util/movefile.py
index 30cb6f1bb..995f6e7e9 100644
--- a/pym/portage/util/movefile.py
+++ b/pym/portage/util/movefile.py
@@ -16,6 +16,16 @@ from portage.localization import _
from portage.process import spawn
from portage.util import writemsg
+if hasattr(_os, "getxattr"):
+ # Python >=3.3
+ def _copyxattr(src, dest):
+ for attr in _os.listxattr(src):
+ _os.setxattr(dest, attr, _os.getxattr(src, attr))
+else:
+ def _copyxattr(src, dest):
+ pass
+ # Maybe call getfattr and setfattr executables.
+
def movefile(src, dest, newmtime=None, sstat=None, mysettings=None,
hardlink_candidates=None, encoding=_encodings['fs']):
"""moves a file from src to dest, preserving all permissions and attributes; mtime will
@@ -162,10 +172,12 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None,
try: # For safety copy then move it over.
if selinux_enabled:
selinux.copyfile(src, dest + "#new")
+ _copyxattr(src, dest + "#new")
selinux.rename(dest + "#new", dest)
else:
- shutil.copyfile(src,dest+"#new")
- os.rename(dest+"#new",dest)
+ shutil.copyfile(src, dest + "#new")
+ _copyxattr(src, dest + "#new")
+ os.rename(dest + "#new", dest)
didcopy=1
except SystemExit as e:
raise