From 44262f797147a9bfaf53a6ef1d2770e60efaa886 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 4 Jun 2007 01:44:34 +0000 Subject: For bug #164655, port quickpkg to python and use the tarfile module for proper handling of symlinks to directories. Thanks to Martin Parm for the initial port. svn path=/main/trunk/; revision=6728 --- pym/portage/dbapi/vartree.py | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'pym') diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 19b54d6c2..60f893f0c 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -2060,3 +2060,54 @@ class dblink(object): def isregular(self): "Is this a regular package (does it have a CATEGORY file? A dblink can be virtual *and* regular)" return os.path.exists(os.path.join(self.dbdir, "CATEGORY")) + +def tar_contents(contents, root, tar, onProgress=None): + from portage import normalize_path + root = normalize_path(root).rstrip(os.path.sep) + os.path.sep + id_strings = {} + maxval = len(contents) + curval = 0 + if onProgress: + onProgress(maxval, 0) + paths = contents.keys() + paths.sort() + for path in paths: + curval += 1 + try: + lst = os.lstat(path) + except OSError, e: + if e.errno != errno.ENOENT: + raise + del e + if onProgress: + onProgress(maxval, curval) + continue + contents_type = contents[path][0] + if path.startswith(root): + arcname = path[len(root):] + else: + raise ValueError("invalid root argument: '%s'" % root) + live_path = path + if 'dir' == contents_type and \ + not stat.S_ISDIR(lst.st_mode) and \ + os.path.isdir(live_path): + # Even though this was a directory in the original ${D}, it exists + # as a symlink to a directory in the live filesystem. It must be + # recorded as a real directory in the tar file to ensure that tar + # can properly extract it's children. + live_path = os.path.realpath(live_path) + tarinfo = tar.gettarinfo(live_path, arcname) + # store numbers instead of real names like tar's --numeric-owner + tarinfo.uname = id_strings.setdefault(tarinfo.uid, str(tarinfo.uid)) + tarinfo.gname = id_strings.setdefault(tarinfo.gid, str(tarinfo.gid)) + + if stat.S_ISREG(lst.st_mode): + f = file(path) + try: + tar.addfile(tarinfo, f) + finally: + f.close() + else: + tar.addfile(tarinfo) + if onProgress: + onProgress(maxval, curval) -- cgit v1.2.3-1-g7c22