From 6f6de0d32cc9b9e1adf65bde3fa0854e6bd26db9 Mon Sep 17 00:00:00 2001 From: Christian Aistleitner Date: Thu, 26 Mar 2015 14:25:03 +0100 Subject: [PATCH] Disentangle BUCK caches for internally built and downloaded artifacts Downloaded artifacts went directly into ~/.gerritcodereview/buck-cache while artifacts built by BUCK went into the directory's `cache` subdirectory: ~/.gerritcodereview/buck-cache/cache . When just walking the file hierarchy on the command line, this `cache` sub-directory is hardly visible, due to all the downloaded artifacts. To increase visibility, we change to * ~/.gerritcodereview/buck-cache/downloaded-artifacts (for downloaded artifacts) * ~/.gerritcodereview/buck-cache/locally-built-artifacts (for artifacts built by buck locally) That way `~/.gerritcodereview/buck-cache` (instead of one directory and 100s files) now only contains two directories. Change-Id: I7327ff6c1736f9af8ea15450949dc6a4bc10b684 --- .buckconfig | 2 +- Documentation/dev-buck.txt | 9 +++++---- tools/download_file.py | 26 +++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/.buckconfig b/.buckconfig index 20954d75bb..7b75225156 100644 --- a/.buckconfig +++ b/.buckconfig @@ -27,4 +27,4 @@ [cache] mode = dir - dir = ~/.gerritcodereview/buck-cache/cache + dir = ~/.gerritcodereview/buck-cache/locally-built-artifacts diff --git a/Documentation/dev-buck.txt b/Documentation/dev-buck.txt index e307391da6..de3e6de04b 100644 --- a/Documentation/dev-buck.txt +++ b/Documentation/dev-buck.txt @@ -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 diff --git a/tools/download_file.py b/tools/download_file.py index 061d67c316..97d982fabc 100755 --- a/tools/download_file.py +++ b/tools/download_file.py @@ -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))