Index: jhbuild/utils/unpack.py
===================================================================
--- jhbuild/utils/unpack.py	(revisión: 0)
+++ jhbuild/utils/unpack.py	(revisión: 0)
@@ -0,0 +1,78 @@
+# Copyright (C) 2007  Alberto Ruiz <aruiz@gnome.org>
+#
+#   unpack.py: helper functions for unpacking compressed packages
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+def unpack_tar_file(localfile, target):
+    import tarfile
+    pkg = tarfile.open(localfile, 'r|*')
+    pkg.extractall(target)
+    pkg.close()
+
+def unpack_zip_file(localfile, target):
+    import zipfile
+    import os
+
+    def attr_check_symlink(attr):
+        return attr == 0xA1ED0000
+
+    def attr_to_file_perm(attr):
+        perm = attr
+        perm &= 0x08FF0000
+        perm >>= 16
+        perm |= 0x00000100
+        return perm
+
+    def attr_to_dir_perm(attr):
+        perm = attr
+        perm &= 0xFFFF0000
+        perm >>= 16
+        perm |= 0x00000100
+        return perm
+
+    def makedirs(dir):
+        if not os.path.isdir(dir):
+            os.makedirs(dir)
+
+    pkg = zipfile.ZipFile(localfile, 'r')
+    for pkg_fileinfo in pkg.filelist:
+	pkg_file = pkg_fileinfo.filename
+        attr = pkg_fileinfo.external_attr
+
+        # Symlink
+        if attr_check_symlink(attr):
+            # This is not supported yet
+            continue
+
+        # Dir
+        if pkg_file.endswith('/'):
+            dir = os.path.join(target, pkg_file)
+            makedirs(dir)
+            os.chmod(dir, attr_to_dir_perm(attr))
+            continue
+
+        # File
+        if '/' in pkg_file:
+            dir = os.path.dirname(pkg_file)
+            dir = os.path.join(target, dir)
+            makedirs(dir)
+            
+        data = pkg.read(pkg_file)
+        file = open(os.path.join(target, pkg_file), 'wb')
+        file.write(data)
+        file.close()
+
+        os.chmod(os.path.join(target, pkg_file), attr_to_file_perm(attr))
Index: jhbuild/modtypes/tarball.py
===================================================================
--- jhbuild/modtypes/tarball.py	(revisión: 1707)
+++ jhbuild/modtypes/tarball.py	(copia de trabajo)
@@ -20,6 +20,8 @@
 __metaclass__ = type
 
 import os
+import tarfile
+import zipfile
 import urlparse
 import urllib2
 
@@ -27,6 +29,7 @@
 from jhbuild.modtypes import Package, register_module_type, get_dependencies
 from jhbuild.utils import httpcache
 from jhbuild.utils.cmds import has_command
+from jhbuild.utils.unpack import unpack_zip_file, unpack_tar_file
 
 jhbuild_directory = os.path.abspath(os.path.join(os.path.dirname(__file__),
                                                  '..', '..'))
@@ -163,15 +166,12 @@
         srcdir = self.get_srcdir(buildscript)
 
         buildscript.set_action('Unpacking', self)
-        if localfile.endswith('.bz2'):
-            buildscript.execute('bunzip2 -dc "%s" | tar xf -' % localfile,
-                                cwd=buildscript.config.checkoutroot)
-        elif localfile.endswith('.gz') or localfile.endswith('.tgz'):
-            buildscript.execute('gunzip -dc "%s" | tar xf -' % localfile,
-                                cwd=buildscript.config.checkoutroot)
-        elif localfile.endswith('.zip'):
-            buildscript.execute('unzip "%s"' % localfile,
-                                cwd=buildscript.config.checkoutroot)
+        if tarfile.is_tarfile(localfile):
+            unpack_tar_file(localfile, buildscript.config.checkoutroot)
+
+        elif zipfile.is_zipfile(localfile):
+            unpack_zip_file(localfile, buildscript.config.checkoutroot)
+
         else:
             raise FatalError("don't know how to handle: %s" % localfile)
         
Index: jhbuild/versioncontrol/tarball.py
===================================================================
--- jhbuild/versioncontrol/tarball.py	(revisión: 1707)
+++ jhbuild/versioncontrol/tarball.py	(copia de trabajo)
@@ -21,12 +21,14 @@
 __metaclass__ = type
 
 import os
+import tarfile, zipfile
 import urlparse
 
 from jhbuild.errors import FatalError, BuildStateError
 from jhbuild.versioncontrol import Repository, Branch, register_repo_type
 from jhbuild.utils.cmds import has_command
 from jhbuild.modtypes import get_branch
+from jhbuild.utils.unpack import unpack_zip_file, unpack_tar_file
 
 jhbuild_directory = os.path.abspath(os.path.join(os.path.dirname(__file__),
                                                  '..', '..'))
@@ -172,16 +174,12 @@
             self._check_tarball()
 
         # now to unpack it
-        if localfile.endswith('.bz2'):
-            buildscript.execute('bunzip2 -dc "%s" | tar xf -' % localfile,
-                                cwd=self.checkoutroot)
-        elif localfile.endswith('.gz') or localfile.endswith('.tgz'):
-            buildscript.execute('gunzip -dc "%s" | tar xf -' % localfile,
-                                cwd=self.checkoutroot)
-        elif localfile.endswith('.zip'):
-            buildscript.execute('unzip "%s"' % localfile,
-                                cwd=self.checkoutroot)
+        if tarfile.is_tarfile(localfile):
+            unpack_tar_file(localfile, self.checkoutroot)
 
+        elif zipfile.is_zipfile(localfile):
+	    unpack_zip_file(localfile, self.checkoutroot)
+
         if not os.path.exists(self.srcdir):
             raise BuildStateError('could not unpack tarball')
 
