Merge "Disentangle BUCK caches for internally built and downloaded artifacts"

This commit is contained in:
David Pursehouse 2015-07-13 08:35:20 +00:00 committed by Gerrit Code Review
commit 52bc11dedf
3 changed files with 31 additions and 6 deletions

View File

@ -27,4 +27,4 @@
[cache]
mode = dir
dir = ~/.gerritcodereview/buck-cache/cache
dir = ~/.gerritcodereview/buck-cache/locally-built-artifacts

View File

@ -510,7 +510,7 @@ The trivial case using a local directory is:
=== Cleaning The Buck Cache
The cache for the Gerrit Code Review project is located in
`~/.gerritcodereview/buck-cache/cache`.
`~/.gerritcodereview/buck-cache/locally-built-artifacts`.
The Buck cache should never need to be manually deleted. If you find yourself
deleting the Buck cache regularly, then it is likely that there is something
@ -519,11 +519,12 @@ wrong with your environment or your workflow.
If you really do need to clean the cache manually, then:
----
rm -rf ~/.gerritcodereview/buck-cache/cache
rm -rf ~/.gerritcodereview/buck-cache/locally-built-artifacts
----
Note that the root `buck-cache` folder should not be deleted as this is where
downloaded artifacts are stored.
Note that the root `buck-cache` folder should not be deleted as it also contains
the `downloaded-artifacts` directory, which holds the artifacts that got
downloaded (not built locally).
[[buck-daemon]]
=== Using Buck daemon

View File

@ -25,7 +25,11 @@ from util import resolve_url
from zipfile import ZipFile, BadZipfile, LargeZipFile
GERRIT_HOME = path.expanduser('~/.gerritcodereview')
CACHE_DIR = path.join(GERRIT_HOME, 'buck-cache')
CACHE_DIR = path.join(GERRIT_HOME, 'buck-cache', 'downloaded-artifacts')
# LEGACY_CACHE_DIR is only used to allow existing workspaces to move already
# downloaded files to the new cache directory.
# Please remove after 3 months (2015-10-07).
LEGACY_CACHE_DIR = path.join(GERRIT_HOME, 'buck-cache')
LOCAL_PROPERTIES = 'local.properties'
@ -85,6 +89,15 @@ def cache_entry(args):
name = '%s-%s' % (path.basename(args.o), h)
return path.join(CACHE_DIR, name)
# Please remove after 3 months (2015-10-07). See LEGACY_CACHE_DIR above.
def legacy_cache_entry(args):
if args.v:
h = args.v
else:
h = sha1(args.u.encode('utf-8')).hexdigest()
name = '%s-%s' % (path.basename(args.o), h)
return path.join(LEGACY_CACHE_DIR, name)
opts = OptionParser()
opts.add_option('-o', help='local output file')
@ -103,8 +116,19 @@ while root_dir:
redirects = download_properties(root_dir)
cache_ent = cache_entry(args)
legacy_cache_ent = legacy_cache_entry(args)
src_url = resolve_url(args.u, redirects)
# Please remove after 3 months (2015-10-07). See LEGACY_CACHE_DIR above.
if not path.exists(cache_ent) and path.exists(legacy_cache_ent):
try:
safe_mkdirs(path.dirname(cache_ent))
except OSError as err:
print('error creating directory %s: %s' %
(path.dirname(cache_ent), err), file=stderr)
exit(1)
shutil.move(legacy_cache_ent, cache_ent)
if not path.exists(cache_ent):
try:
safe_mkdirs(path.dirname(cache_ent))