aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArfrever Frehtes Taifersar Arahesis <Arfrever@Gentoo.Org>2011-12-10 00:51:31 +0100
committerArfrever Frehtes Taifersar Arahesis <Arfrever@Gentoo.Org>2011-12-10 00:51:31 +0100
commitb5b277f1c03ceee6b00577a693e8c3f0b42d32aa (patch)
tree0cd8623bb8ddcee4ac7a2c269769de1b080e4074 /pym/portage/util/movefile.py
parentdata.py: grp/pwd struct attrs, not indexes (diff)
downloadportage-b5b277f1c03ceee6b00577a693e8c3f0b42d32aa.tar.gz
portage-b5b277f1c03ceee6b00577a693e8c3f0b42d32aa.tar.bz2
portage-b5b277f1c03ceee6b00577a693e8c3f0b42d32aa.zip
portage.util.movefile._copyxattr(): Support usage of getfattr and
setfattr executables.
Diffstat (limited to 'pym/portage/util/movefile.py')
-rw-r--r--pym/portage/util/movefile.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/pym/portage/util/movefile.py b/pym/portage/util/movefile.py
index fe4150137..9507d83a2 100644
--- a/pym/portage/util/movefile.py
+++ b/pym/portage/util/movefile.py
@@ -7,6 +7,7 @@ import errno
import os as _os
import shutil as _shutil
import stat
+import subprocess
import portage
from portage import bsd_chflags, _encodings, _os_overrides, _selinux, \
@@ -22,14 +23,32 @@ def _apply_stat(src_stat, dest):
_os.chmod(dest, stat.S_IMODE(src_stat.st_mode))
if hasattr(_os, "getxattr"):
- # Python >=3.3
+ # Python >=3.3 and GNU/Linux
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.
+ _devnull = open("/dev/null", "w")
+ try:
+ subprocess.call(["getfattr", "--version"], stdout=_devnull)
+ subprocess.call(["setfattr", "--version"], stdout=_devnull)
+ _has_getfattr_and_setfattr = True
+ except OSError:
+ _has_getfattr_and_setfattr = False
+ _devnull.close()
+ if _has_getfattr_and_setfattr:
+ def _copyxattr(src, dest):
+ getfattr_process = subprocess.Popen(["getfattr", "-d", "--absolute-names", src], stdout=subprocess.PIPE)
+ getfattr_process.wait()
+ extended_attributes = getfattr_process.stdout.readlines()
+ getfattr_process.stdout.close()
+ if extended_attributes:
+ extended_attributes[0] = b"# file: " + _unicode_encode(dest) + b"\n"
+ setfattr_process = subprocess.Popen(["setfattr", "--restore=-"], stdin=subprocess.PIPE)
+ setfattr_process.communicate(input=b"".join(extended_attributes))
+ else:
+ def _copyxattr(src, dest):
+ pass
def movefile(src, dest, newmtime=None, sstat=None, mysettings=None,
hardlink_candidates=None, encoding=_encodings['fs']):