Delete corrupt cache entries from ~/.gerritcodereview/buck-cache

If the SHA-1 does not match the downloaded file content, delete the
file from the cache. This allows a user to fix whatever connectivity
problem led to the corruption and re-run buck build to download
the correct content.

Change-Id: I2f72fb2b187675ec9d5cda650d8982bc93a00189
This commit is contained in:
Shawn Pearce
2013-05-22 08:54:04 -07:00
parent e1f8288fc7
commit eb2eeec491

View File

@@ -17,7 +17,7 @@ from __future__ import print_function
from hashlib import sha1 from hashlib import sha1
from optparse import OptionParser from optparse import OptionParser
from os import link, makedirs, path, symlink from os import link, makedirs, path, remove, symlink
import shutil import shutil
from subprocess import check_call, CalledProcessError from subprocess import check_call, CalledProcessError
from sys import stderr from sys import stderr
@@ -135,12 +135,15 @@ if not path.exists(cache_ent):
if args.v: if args.v:
have = hashfile(cache_ent) have = hashfile(cache_ent)
if args.v != have: if args.v != have:
o = cache_ent[len(root_dir) + 1:]
print(( print((
'%s:\n' + '%s:\n' +
'expected %s\n' + 'expected %s\n' +
'received %s\n' + 'received %s\n') % (src_url, args.v, have), file=stderr)
' %s\n') % (src_url, args.v, have, o), file=stderr) try:
remove(cache_ent)
except OSError as err:
if path.exists(cache_ent):
print('error removing %s: %s' % (cache_ent, err), file=stderr)
exit(1) exit(1)
exclude = [] exclude = []