util: Check compression type passed to uncompress

Also add "gz" as an alias for "gzip".
This commit is contained in:
Fatih Aşıcı
2010-06-15 18:10:18 +00:00
parent 9018d1f4fe
commit a34c3c0041
2 changed files with 15 additions and 7 deletions
+1
View File
@@ -587,6 +587,7 @@ class Archive:
'tarZ': ArchiveTarZ,
'tar': ArchiveTar,
'zip': ArchiveZip,
'gz': ArchiveGzip,
'gzip': ArchiveGzip,
'bz2': ArchiveBzip2,
'bzip2': ArchiveBzip2,
+14 -7
View File
@@ -524,16 +524,23 @@ def sha1_data(data):
def uncompress(patchFile, compressType="gz", targetDir=""):
"""Uncompress the file and return the new path."""
archive = pisi.archive.Archive(patchFile, compressType)
archive.unpack(targetDir)
formats = ("gz", "gzip", "bz2", "bzip2", "lzma", "xz")
if compressType not in formats:
raise Error(_("Compression type is not valid: '%s'") % compressType)
# for bzip2, file extension is bz2
if compressType == "bzip2":
compressType = "bz2"
archive = pisi.archive.Archive(patchFile, compressType)
try:
archive.unpack(targetDir)
except Exception, msg:
raise Error(_("Error while decompressing %s: %s") % (patchFile, msg))
# FIXME: Get file path from Archive instance
filePath = join_path(targetDir, os.path.basename(patchFile))
# remove suffix from file cause its uncompressed now
filePath = join_path(targetDir, os.path.basename(patchFile))
return filePath.split(".%s" % compressType)[0]
extensions = {"gzip": "gz", "bzip2": "bz2"}
extension = extensions.get(compressType, compressType)
return filePath.split(".%s" % extension)[0]
def do_patch(sourceDir, patchFile, level=0, name=None, reverse=False):