diff --git a/ZipStorage.py b/ZipStorage.py index 8e5b981..36f8d61 100644 --- a/ZipStorage.py +++ b/ZipStorage.py @@ -213,6 +213,23 @@ class ZipChildDir(ZipItem, StorageFolder): def __repr__(self): return '' % len(self.pathObjmap) +def tryTar(path): + # Try to see if it's a tar file + if path[-2:] == 'gz': + comp = tarfile.TAR_GZIPPED + elif path[-3:] == 'bz2': + comp = tarfile.TAR_BZ2 + else: + comp = tarfile.TAR_PLAIN + return tarfile.TarFileCompat(path, compression=comp) + +def canHandle(path): + if zipfile.is_zipfile(path): + return True + + #tar is cheaper on __init__ than zipfile + return tryTar(path) + def genZipFile(path): try: return zipfile.ZipFile(path) @@ -222,14 +239,7 @@ def genZipFile(path): pass try: - # Try to see if it's a tar file - if path[-2:] == 'gz': - comp = tarfile.TAR_GZIPPED - elif path[-3:] == 'bz2': - comp = tarfile.TAR_BZ2 - else: - comp = tarfile.TAR_PLAIN - return tarfile.TarFileCompat(path, compression=comp) + return tryTar(path) except: #import traceback #traceback.print_exc(file=log.logfile) @@ -252,6 +262,7 @@ class ZipObject(FSObject, StorageFolder): self.zip = genZipFile(self.FSpath) hier = buildNameHier(self.zip.namelist(), self.zip.infolist()) + print 'zip len:', len(hier) doupdate = False children = sets.Set(hier.keys()) for i in self.pathObjmap.keys(): @@ -288,7 +299,7 @@ class ZipObject(FSObject, StorageFolder): def detectzipfile(path, fobj): try: - genZipFile(path) + canHandle(path) except: return None, None