Cache downloaded JAR files in ~/.gerritcodereview/buck-cache

Instead of caching downloaded files in `./buck-cache` in the
working folder, cache them in `.gerritcodereview/buck-cache` in
the user's home folder.

This offers two advantages:

- Cached files are not lost if the working folder is removed, or
  untracked files are removed with `git clean`.

- The same cached files can be shared between multiple working
  folders, i.e. if the developer has separate workspaces to work
  on different target branches.

Change-Id: I3e132df85c43431c2454421b1de0d9e901679540
This commit is contained in:
David Pursehouse
2013-05-17 13:46:40 +09:00
parent fec1537a56
commit 45286f196a

View File

@@ -28,7 +28,8 @@ REPO_ROOTS = {
'MAVEN_CENTRAL': 'http://repo1.maven.org/maven2',
}
GERRIT_HOME = '~/.gerritcodereview'
GERRIT_HOME = path.expanduser('~/.gerritcodereview')
CACHE_DIR = path.join(GERRIT_HOME, 'buck-cache')
LOCAL_PROPERTIES = 'local.properties'
@@ -64,7 +65,7 @@ def download_properties(root_dir):
p = {}
local_prop = path.join(root_dir, LOCAL_PROPERTIES)
if not path.isfile(local_prop):
local_prop = path.join(path.expanduser(GERRIT_HOME), LOCAL_PROPERTIES)
local_prop = path.join(GERRIT_HOME, LOCAL_PROPERTIES)
if path.isfile(local_prop):
try:
with open(local_prop) as fd:
@@ -77,13 +78,13 @@ def download_properties(root_dir):
pass
return p
def cache_entry(root_dir, args):
def cache_entry(args):
if args.v:
h = args.v
else:
h = sha1(args.u).hexdigest()
name = '%s-%s' % (path.basename(args.o), h)
return path.join(root_dir, 'buck-cache', name)
return path.join(CACHE_DIR, name)
def resolve_url(url, redirects):
s = url.find(':')
@@ -115,7 +116,7 @@ while root_dir:
break
redirects = download_properties(root_dir)
cache_ent = cache_entry(root_dir, args)
cache_ent = cache_entry(args)
src_url = resolve_url(args.u, redirects)
if not path.exists(cache_ent):