1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

zipnum: backport fix for #173, paths specified in a zipnum .loc file are relative to the .loc file, not to

the working dir of the application
warnings: don't warn on .gz cdx files
This commit is contained in:
Ilya Kreymer 2016-03-31 13:09:57 -07:00
parent ba7ac56230
commit e5ef51363c
5 changed files with 16 additions and 7 deletions

View File

@ -176,8 +176,8 @@ class CDXServer(BaseCDXServer):
if filename.endswith(('.summary', '.idx')):
return ZipNumCluster(filename, config)
# no warning for .loc
if not filename.endswith('.loc'):
# no warning for .loc or .gz (zipnum)
if not filename.endswith(('.loc', '.gz')):
logging.warn('skipping unrecognized URI: %s', filename)
return None

View File

@ -149,7 +149,7 @@ Traceback (most recent call last):
Exception: No Locations Found for: foo
>>> zip_test_err(url='http://iana.org/x', matchType='exact')
>>> zip_test_err(url='http://iana.org/x', matchType='exact') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
IOError: [Errno 2] No such file or directory: './sample_archive/invalid'

View File

@ -51,11 +51,20 @@ class LocMapResolver(object):
# update loc file mtime
self.loc_mtime = new_mtime
local_dir = os.path.dirname(self.loc_filename)
def res_path(pathname):
if '://' not in pathname:
pathname = os.path.join(local_dir, pathname)
return pathname
logging.debug('Loading loc from: ' + self.loc_filename)
with open(self.loc_filename, 'rb') as fh:
for line in fh:
parts = line.rstrip().split('\t')
self.loc_map[parts[0]] = parts[1:]
paths = [res_path(pathname) for pathname in parts[1:]]
self.loc_map[parts[0]] = paths
def __call__(self, part, query):
return self.loc_map[part]

View File

@ -1,3 +1,3 @@
bar ./sample_archive/invalid
bar invalid
foo2
zipnum ./sample_archive/x-bad-path-to-ignore-x ./sample_archive/zipcdx/zipnum-sample.cdx.gz
zipnum x-bad-path-to-ignore-x zipnum-sample.cdx.gz

View File

@ -1 +1 @@
zipnum ./sample_archive/x-bad-path-to-ignore-x ./sample_archive/zipcdx/zipnum-sample.cdx.gz
zipnum x-bad-path-to-ignore-x zipnum-sample.cdx.gz