From ddc9dbc832b3424da722f7442cf33327423735a6 Mon Sep 17 00:00:00 2001 From: Arfrever Frehtes Taifersar Arahesis Date: Tue, 29 Nov 2011 02:26:04 +0100 Subject: Preserve extended attributes on regular files when using Python >=3.3. --- pym/portage/util/movefile.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'pym/portage/util/movefile.py') 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 -- cgit v1.2.3-1-g7c22