[PATCH mock] Fixup of *pack() methods

Enrico Scholz enrico.scholz at informatik.tu-chemnitz.de
Sat May 5 17:03:49 UTC 2007


Cache operations do not seem to work and use deprecated options; e.g.

| DEBUG: Executing tar -zlcf /var/lib/mock/root-cache/fedora-development-i386-core.tar.gz root
| tar: Semantics of -l option will change in the future releases.
| tar: Please use --one-file-system option instead.
| tar: root: Cannot stat: No such file or directory
| tar: Error exit delayed from previous errors

This patch fixes caching operations and enhances them in some aspects
(e.g. do not cache downloaded packages).

Signed-off-by: Enrico Scholz <enrico.scholz at informatik.tu-chemnitz.de>
---

 mock.py |   49 ++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/mock.py b/mock.py
index 573bb6e..3762324 100644
--- a/mock.py
+++ b/mock.py
@@ -239,15 +239,29 @@ class Root:
         else:
             return self._state
 
-    def unpack(self):
-        self.state('unpack_cache')
+    def __get_tar_compress_opts(self):
         if self.cache_file.find(".bz2") != -1:
-            opts = "-jxpf"
+            return ["-j",]
         elif self.cache_file.find(".gz") != -1:
-            opts = "-zxpf"
+            return ["-z",]
         else:
-            opts = "-xpf"
-        cmd = '%s %s %s %s' % (self.config['unpack_cmd'], opts, self.basedir, self.cache_file)
+            return []
+
+    def unpack(self):
+        self.state('unpack_cache')
+
+        opts=self.__get_tar_compress_opts()
+        opts.extend([
+            '-xpf',
+            self.cache_file,
+            '-C',
+            self.basedir])
+
+        # the quoting by map(...) is hacky; it would be better to use
+        # correct datatypes for the do*() methods
+        cmd = '%s %s' % (self.config['unpack_cmd'],
+                         ' '.join(map(lambda x: '"%s"' % x, opts)))
+        
         self.debug("unpacking cache: %s" % cmd)
         (retval, output) = self.do_elevated(cmd)
         return retval
@@ -255,13 +269,22 @@ class Root:
     def pack(self):
         self.state('create_cache')
         self._ensure_dir(os.path.join(self.config['basedir'], self.config['cache_topdir']))
-        if self.cache_file.find(".bz2") != -1:
-            opts = "-jlcf"
-        elif self.cache_file.find(".gz") != -1:
-            opts = "-zlcf"
-        else:
-            opts = "-clf"
-        cmd = '%s %s %s root' % (self.config['pack_cmd'], opts, self.cache_file)
+
+        opts=self.__get_tar_compress_opts()
+        opts.extend([
+            '-cf',
+            self.cache_file,
+            '--one-file-system',
+            '--exclude=__db*',
+            '--exclude=root/var/cache/yum/*/headers',
+            '--exclude=root/var/cache/yum/*/packages',
+            'root'
+            ])
+
+        cmd  = 'cd "%s" && %s %s' % (self.basedir,
+                                     self.config['pack_cmd'],
+                                     ' '.join(map(lambda x: '"%s"' % x, opts)))
+
         self.debug("creating cache: %s" % cmd)
         (retval, output) = self.do_elevated(cmd)
         return retval




More information about the buildsys mailing list