From 7c87f05506348b7512705794cc240db4442c3e30 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Wed, 27 Aug 2014 11:15:26 +0900 Subject: [PATCH] Bug 1058565 - Correctly handle bad cache data. r=mshal --- cache.py | 7 ++----- server.py | 9 ++++++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cache.py b/cache.py index e2527822..279388c7 100644 --- a/cache.py +++ b/cache.py @@ -4,7 +4,7 @@ import shutil from cStringIO import StringIO -from zipfile import ZipFile, ZIP_DEFLATED, BadZipfile +from zipfile import ZipFile, ZIP_DEFLATED class CacheData(object): @@ -22,10 +22,7 @@ class CacheData(object): def __init__(self, data=None): self._data = StringIO(data) if data else StringIO() self._obj = {} - try: - self._zip = ZipFile(self._data, 'r' if data else 'w', ZIP_DEFLATED) - except BadZipfile: - self._zip = ZipFile(self._data, 'w', ZIP_DEFLATED) + self._zip = ZipFile(self._data, 'r' if data else 'w', ZIP_DEFLATED) def __getitem__(self, key): if key not in self._obj: diff --git a/server.py b/server.py index 71a7611f..5c9f8ec0 100644 --- a/server.py +++ b/server.py @@ -254,6 +254,7 @@ def _run_command(job): outputs = {key: os.path.join(cwd, path) if cwd else path for key, path in parsed_args['output'].items()} + cache = None if preprocessed: # Compute the key corresponding to the preprocessor output, the command # line, and the compiler. @@ -264,7 +265,11 @@ def _run_command(job): # Get cached data if there is. data = storage.get(cache_key) if data: - cache = CacheData(data) + try: + cache = CacheData(data) + except: + pass + if cache: for key, path in outputs.items(): with open(path, 'wb') as obj: obj.write(cache[key]) @@ -289,8 +294,6 @@ def _run_command(job): cache[key] = f.read() except: cache = None - else: - cache = None if cache: status = 'miss'