]> git.ipfire.org Git - pakfire.git/commitdiff
Fixing support for capabilities.
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 10 Mar 2011 14:52:10 +0000 (15:52 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 10 Mar 2011 14:52:10 +0000 (15:52 +0100)
This code should work with Python 2.6 as well.

pakfire/packages/__init__.py
pakfire/packages/file.py
pakfire/packages/packager.py
pakfire/transaction.py
po/pakfire.pot

index af5711871dbc6006a22d6a14a47f0354ff6a69db..440e874bbe087748b8278e57e851106826fab1b1 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/python
 
 from binary import BinaryPackage
+from file import InnerTarFile
 from installed import DatabasePackage, InstalledPackage
 from source import SourcePackage
 from virtual import VirtualPackage
index 9b50aae15f2b02d63002284cec60a9d6a5b2526b..81b816aa53bdddb632a67e4fe9978074f1926ce7 100644 (file)
@@ -1,8 +1,10 @@
 #!/usr/bin/python
 
-import tarfile
+import logging
 import os
 import re
+import tarfile
+import xattr
 
 import util
 
@@ -10,6 +12,65 @@ from pakfire.errors import FileError
 
 from base import Package
 
+class InnerTarFile(tarfile.TarFile):
+       SUPPORTED_XATTRS = ("security.capability",)
+
+       def __init__(self, *args, **kwargs):
+               # Force the PAX format.
+               kwargs["format"] = tarfile.PAX_FORMAT
+
+               tarfile.TarFile.__init__(self, *args, **kwargs)
+
+       def add(self, name, arcname=None, recursive=None, exclude=None, filter=None):
+               """
+                       Emulate the add function with xattrs support.
+               """
+               tarinfo = self.gettarinfo(name, arcname)
+
+               if tarinfo.isreg():
+                       attrs = xattr.get_all(name)
+
+                       for attr, val in attrs:
+                               # Skip all attrs that are not supported (e.g. selinux).
+                               if not attr in self.SUPPORTED_XATTRS:
+                                       continue
+
+                               logging.debug("Saving xattr %s=%s from %s" % (attr, val, name))
+
+                               tarinfo.pax_headers[attr] = val
+
+               # Append the tar header and data to the archive.
+                       f = tarfile.bltn_open(name, "rb")
+                       self.addfile(tarinfo, f)
+                       f.close()
+
+               elif tarinfo.isdir():
+                       self.addfile(tarinfo)
+                       if recursive:
+                               for f in os.listdir(name):
+                                       self.add(os.path.join(name, f), os.path.join(arcname, f),
+                                                       recursive, exclude, filter)
+
+               else:
+                       self.addfile(tarinfo)
+
+       def extract(self, member, path=""):
+               # Extract file the normal way...
+               tarfile.TarFile.extract(self, member, path)
+
+               # ...and then apply the extended attributes.
+               if member.pax_headers:
+                       target = os.path.join(path, member.name)
+
+                       for attr, val in member.pax_headers.items():
+                               # Skip all attrs that are not supported (e.g. selinux).
+                               if not attr in self.SUPPORTED_XATTRS:
+                                       continue
+
+                               logging.debug("Restoring xattr %s=%s to %s" % (attr, val, target))
+                               xattr.set(target, attr, val)
+
+
 class FilePackage(Package):
        """
                This class is a wrapper that reads package data from the (outer)
index 66f2872b75a977aca0d04078f36dc70b6d5f91c4..12fb5b23c10f543ba8b3d8c3aae8d0aa99778533 100644 (file)
@@ -18,50 +18,7 @@ import pakfire.compress
 from pakfire.constants import *
 from pakfire.i18n import _
 
-
-# XXX disable because python 2.6 does not support tarfile with filter
-#
-#class InnerTarFile(tarfile.TarFile):
-#      def __init__(self, *args, **kwargs):
-#              # Force the pax format
-#              kwargs["format"] = tarfile.PAX_FORMAT
-#
-#              if kwargs.has_key("env"):
-#                      self.env = kwargs.pop("env")
-#
-#              tarfile.TarFile.__init__(self, *args, **kwargs)
-#
-#      def __filter_xattrs(self, tarinfo):
-#              logging.debug("Adding file: %s" % tarinfo.name)
-#
-#              filename = self.env.chrootPath(self.env.buildroot, tarinfo.name)
-#
-#              # xattrs do only exists for regular files. If we don't have one,
-#              # simply skip.
-#              if os.path.isfile(filename):
-#                      for attr, value in xattr.get_all(filename):
-#                              tarinfo.pax_headers[attr] = value
-#
-#                              logging.debug("  xattr: %s=%s" % (attr, value))
-#
-#              return tarinfo
-#
-#      def add(self, *args, **kwargs):
-#              # Add filter for xattrs if no other filter is set.
-#              if not kwargs.has_key("filter") and len(args) < 5:
-#                      kwargs["filter"] = self.__filter_xattrs
-#
-#              tarfile.TarFile.add(self, *args, **kwargs)
-
-class InnerTarFile(tarfile.TarFile):
-       def __init__(self, *args, **kwargs):
-               kwargs["format"] = tarfile.PAX_FORMAT
-
-               if kwargs.has_key("env"):
-                       del kwargs["env"]
-
-               tarfile.TarFile.__init__(self, *args, **kwargs)
-
+from file import InnerTarFile
 
 # XXX this is totally ugly and needs to be done right!
 
@@ -130,7 +87,7 @@ class Packager(object):
                tar.close()
 
        def create_tarball(self, compress="xz"):
-               tar = InnerTarFile(self.archive_files["data.img"], mode="w", env=self.env)
+               tar = InnerTarFile(self.archive_files["data.img"], mode="w")
 
                includes = []
                excludes = []
@@ -188,7 +145,7 @@ class Packager(object):
                        file_tar = file_real[len(self.env.chrootPath(self.env.buildroot)) + 1:]
                        file_tmp = os.path.join(self.tempdir, file_tar)
 
-                       tar.add(file_real, arcname=file_tar, recursive=False)
+                       tar.add(file_real, arcname=file_tar)
 
                        # Record the packaged file to the filelist.
                        filelist.write("/%s\n" % file_tar)
index f77337428d8b755c476f9548108ee1085a96151b..b903ed72e8dfa71b97fa116bc053773fd00764f2 100644 (file)
@@ -184,7 +184,7 @@ class ActionInstall(Action):
                        payload = open(tempf)
 
                # Open the tarball in the package.
-               payload_archive = tarfile.open(fileobj=payload)
+               payload_archive = packages.InnerTarFile.open(fileobj=payload)
 
                members = payload_archive.getmembers()
 
index dff4e14adf290bd3ea4bf594db0627d711175162..aca1645a5e88cc27ee25d034fb5f6a0f07c26135 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2011-03-10 11:38+0100\n"
+"POT-Creation-Date: 2011-03-10 15:19+0100\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"