This code should work with Python 2.6 as well.
#!/usr/bin/python
from binary import BinaryPackage
+from file import InnerTarFile
from installed import DatabasePackage, InstalledPackage
from source import SourcePackage
from virtual import VirtualPackage
#!/usr/bin/python
-import tarfile
+import logging
import os
import re
+import tarfile
+import xattr
import util
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)
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!
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 = []
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)
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()
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"