summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Withnall <philip.withnall@collabora.co.uk>2015-01-05 10:05:51 +0000
committerOwen W. Taylor <otaylor@fishsoup.net>2015-02-23 17:38:48 -0500
commitd3ec0afadaae70b64c80c55155b8cdf45b5ac2ef (patch)
treeaccfeac9b3a429499a18beacbc0e4a87689df22b
parent76814e7170b4e898b05e79f26cd2a7ee72501005 (diff)
downloadgit-bz-d3ec0afadaae70b64c80c55155b8cdf45b5ac2ef.tar.gz
Move cache data to XDG_CACHE_HOME
So the cache file will now typically be ~/.cache/git-bz-cache. https://bugzilla.gnome.org/show_bug.cgi?id=674020
-rwxr-xr-xgit-bz19
1 files changed, 17 insertions, 2 deletions
diff --git a/git-bz b/git-bz
index 3b4afa3..ce6f0b0 100755
--- a/git-bz
+++ b/git-bz
@@ -83,6 +83,7 @@ git_config = {
import base64
import cPickle as pickle
from ConfigParser import RawConfigParser, NoOptionError
+import errno
import httplib
import io
import optparse
@@ -747,15 +748,29 @@ def encode_multipart_formdata(fields, files=None):
# ===============================================
CACHE_EXPIRY_TIME = 3600 * 24 # one day
+xdg_cache_home = os.environ.get('XDG_CACHE_HOME',
+ os.path.join(os.path.expanduser('~'),
+ '.cache'))
+cache_filename = os.path.join(xdg_cache_home, 'git-bz-cache')
class Cache(object):
def __init__(self):
self.cfp = None
def __ensure(self, host):
+ # Ensure the cache directory exists.
+ cache_dir = os.path.dirname(cache_filename)
+ try:
+ os.makedirs(cache_dir, 0700)
+ except OSError as exc:
+ if exc.errno == errno.EEXIST and os.path.isdir(cache_dir):
+ pass
+ else:
+ raise
+
if self.cfp == None:
self.cfp = RawConfigParser()
- self.cfp.read(os.path.expanduser("~/.git-bz-cache"))
+ self.cfp.read(cache_filename)
if self.cfp.has_section(host):
if time.time() > self.cfp.getfloat(host, "expires"):
@@ -775,7 +790,7 @@ class Cache(object):
def set(self, host, key, value):
self.__ensure(host)
self.cfp.set(host, key, pickle.dumps(value))
- f = open(os.path.expanduser("~/.git-bz-cache"), "w")
+ f = open(cache_filename, "w")
self.cfp.write(f)
f.close()