Browse Source

make it so we don't have to fully open a zip file to know it is

one..  This speeds up detection of large zip files..

[git-p4: depot-paths = "//depot/": change = 1129]
replace/b43bf02ddeddd088c0e6b94974ca1a46562eb3db
John-Mark Gurney 17 years ago
parent
commit
5149869959
1 changed files with 20 additions and 9 deletions
  1. +20
    -9
      ZipStorage.py

+ 20
- 9
ZipStorage.py View File

@@ -213,6 +213,23 @@ class ZipChildDir(ZipItem, StorageFolder):
def __repr__(self):
return '<ZipChildDir: len: %d>' % 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



||||||
x
 
000:0
Loading…
Cancel
Save