util: Check compression type passed to uncompress
Also add "gz" as an alias for "gzip".
This commit is contained in:
@@ -587,6 +587,7 @@ class Archive:
|
|||||||
'tarZ': ArchiveTarZ,
|
'tarZ': ArchiveTarZ,
|
||||||
'tar': ArchiveTar,
|
'tar': ArchiveTar,
|
||||||
'zip': ArchiveZip,
|
'zip': ArchiveZip,
|
||||||
|
'gz': ArchiveGzip,
|
||||||
'gzip': ArchiveGzip,
|
'gzip': ArchiveGzip,
|
||||||
'bz2': ArchiveBzip2,
|
'bz2': ArchiveBzip2,
|
||||||
'bzip2': ArchiveBzip2,
|
'bzip2': ArchiveBzip2,
|
||||||
|
|||||||
+14
-7
@@ -524,16 +524,23 @@ def sha1_data(data):
|
|||||||
|
|
||||||
def uncompress(patchFile, compressType="gz", targetDir=""):
|
def uncompress(patchFile, compressType="gz", targetDir=""):
|
||||||
"""Uncompress the file and return the new path."""
|
"""Uncompress the file and return the new path."""
|
||||||
archive = pisi.archive.Archive(patchFile, compressType)
|
formats = ("gz", "gzip", "bz2", "bzip2", "lzma", "xz")
|
||||||
archive.unpack(targetDir)
|
if compressType not in formats:
|
||||||
|
raise Error(_("Compression type is not valid: '%s'") % compressType)
|
||||||
|
|
||||||
# for bzip2, file extension is bz2
|
archive = pisi.archive.Archive(patchFile, compressType)
|
||||||
if compressType == "bzip2":
|
try:
|
||||||
compressType = "bz2"
|
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
|
# remove suffix from file cause its uncompressed now
|
||||||
filePath = join_path(targetDir, os.path.basename(patchFile))
|
extensions = {"gzip": "gz", "bzip2": "bz2"}
|
||||||
return filePath.split(".%s" % compressType)[0]
|
extension = extensions.get(compressType, compressType)
|
||||||
|
return filePath.split(".%s" % extension)[0]
|
||||||
|
|
||||||
|
|
||||||
def do_patch(sourceDir, patchFile, level=0, name=None, reverse=False):
|
def do_patch(sourceDir, patchFile, level=0, name=None, reverse=False):
|
||||||
|
|||||||
Reference in New Issue
Block a user