fix crash when using 'skip=false' and archive (fixes #1023)

Separating the archive check from pathfmt.exists() in b5243297
had some unintended side effects.

It is also not possible to monkey-patch a dunder method like
__contains__ because of the special method lookup that gets
performed for them.
pull/1034/head
Mike Fährmann 4 years ago
parent aeb0d32333
commit d5fa716d89
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -228,7 +228,7 @@ class DownloadJob(Job):
for pp in postprocessors: for pp in postprocessors:
pp.prepare(pathfmt) pp.prepare(pathfmt)
if archive and kwdict in archive: if archive and archive.check(kwdict):
pathfmt.fix_extension() pathfmt.fix_extension()
self.handle_skip() self.handle_skip()
return return
@ -385,8 +385,23 @@ class DownloadJob(Job):
self.sleep = config("sleep") self.sleep = config("sleep")
if not config("download", True): if not config("download", True):
# monkey-patch method to do nothing and always return True
self.download = pathfmt.fix_extension self.download = pathfmt.fix_extension
archive = config("archive")
if archive:
path = util.expand_path(archive)
try:
if "{" in path:
path = util.Formatter(path).format_map(kwdict)
self.archive = util.DownloadArchive(path, self.extractor)
except Exception as exc:
self.extractor.log.warning(
"Failed to open download archive at '%s' ('%s: %s')",
path, exc.__class__.__name__, exc)
else:
self.extractor.log.debug("Using download archive '%s'", path)
skip = config("skip", True) skip = config("skip", True)
if skip: if skip:
self._skipexc = None self._skipexc = None
@ -401,21 +416,10 @@ class DownloadJob(Job):
self._skipcnt = 0 self._skipcnt = 0
self._skipmax = text.parse_int(smax) self._skipmax = text.parse_int(smax)
else: else:
# monkey-patch methods to always return False
pathfmt.exists = lambda x=None: False pathfmt.exists = lambda x=None: False
if self.archive:
archive = config("archive") self.archive.check = pathfmt.exists
if archive:
path = util.expand_path(archive)
try:
if "{" in path:
path = util.Formatter(path).format_map(kwdict)
self.archive = util.DownloadArchive(path, self.extractor)
except Exception as exc:
self.extractor.log.warning(
"Failed to open download archive at '%s' ('%s: %s')",
path, exc.__class__.__name__, exc)
else:
self.extractor.log.debug("Using download archive '%s'", path)
postprocessors = self.extractor.config_accumulate("postprocessors") postprocessors = self.extractor.config_accumulate("postprocessors")
if postprocessors: if postprocessors:

@ -941,7 +941,7 @@ class DownloadArchive():
"archive-format", extractor.archive_fmt) "archive-format", extractor.archive_fmt)
).format_map ).format_map
def __contains__(self, kwdict): def check(self, kwdict):
"""Return True if the item described by 'kwdict' exists in archive""" """Return True if the item described by 'kwdict' exists in archive"""
key = kwdict["_archive_key"] = self.keygen(kwdict) key = kwdict["_archive_key"] = self.keygen(kwdict)
self.cursor.execute( self.cursor.execute(

Loading…
Cancel
Save