зеркало из https://github.com/mozilla/sccache.git
Bug 1058565 - Correctly handle bad cache data. r=mshal
This commit is contained in:
Родитель
6938a9b865
Коммит
7c87f05506
5
cache.py
5
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)
|
||||
|
||||
def __getitem__(self, key):
|
||||
if key not in self._obj:
|
||||
|
|
|
@ -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:
|
||||
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'
|
||||
|
|
Загрузка…
Ссылка в новой задаче