summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lepus.uberspace.de>2016-01-01 01:25:00 +0100
committerhut <hut@lepus.uberspace.de>2016-01-01 01:25:00 +0100
commit951a95c2abbbf682fa087d567542b0cd76afcda3 (patch)
tree34b609c56c6fcec9b1e34960d29d7c657cdab4cc
parentcb6e8a6a2a4eb85eff69b479236d362906b78b5b (diff)
downloadranger-951a95c2abbbf682fa087d567542b0cd76afcda3.tar.gz
core.main: Check XDG_CACHE_HOME, fixes #442
-rw-r--r--ranger/core/actions.py6
-rw-r--r--ranger/core/main.py13
2 files changed, 12 insertions, 7 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index cbf75dbf..bd9be223 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -876,12 +876,12 @@ class Actions(FileManagerAware, SettingsAware):
 
     if version_info[0] == 3:
         def sha1_encode(self, path):
-            return os.path.join(ranger.CACHEDIR,
+            return os.path.join(ranger.arg.cachedir,
                     sha1(path.encode('utf-8', 'backslashreplace')) \
                             .hexdigest()) + '.jpg'
     else:
         def sha1_encode(self, path):
-            return os.path.join(ranger.CACHEDIR,
+            return os.path.join(ranger.arg.cachedir,
                     sha1(path).hexdigest()) + '.jpg'
 
     def get_preview(self, file, width, height):
@@ -933,7 +933,7 @@ class Actions(FileManagerAware, SettingsAware):
                     data['loading'] = False
                     return path
 
-                cacheimg = os.path.join(ranger.CACHEDIR, self.sha1_encode(path))
+                cacheimg = os.path.join(ranger.arg.cachedir, self.sha1_encode(path))
                 if (os.path.isfile(cacheimg) and os.path.getmtime(cacheimg) > os.path.getmtime(path)):
                     data['foundpreview'] = True
                     data['imagepreview'] = True
diff --git a/ranger/core/main.py b/ranger/core/main.py
index 5aa08a93..39d682f7 100644
--- a/ranger/core/main.py
+++ b/ranger/core/main.py
@@ -117,9 +117,8 @@ def main():
 
         # Create cache directory
         if fm.settings.preview_images and fm.settings.use_preview_script:
-            from ranger import CACHEDIR
-            if not os.path.exists(CACHEDIR):
-                os.makedirs(CACHEDIR)
+            if not os.path.exists(arg.cachedir):
+                os.makedirs(arg.cachedir)
 
         # Run the file manager
         fm.initialize()
@@ -179,7 +178,7 @@ def parse_arguments():
     """Parse the program arguments"""
     from optparse import OptionParser, SUPPRESS_HELP
     from os.path import expanduser
-    from ranger import CONFDIR, USAGE, VERSION
+    from ranger import CONFDIR, CACHEDIR, USAGE, VERSION
     from ranger.ext.openstruct import OpenStruct
 
     if 'XDG_CONFIG_HOME' in os.environ and os.environ['XDG_CONFIG_HOME']:
@@ -187,6 +186,11 @@ def parse_arguments():
     else:
         default_confdir = CONFDIR
 
+    if 'XDG_CACHE_HOME' in os.environ and os.environ['XDG_CACHE_HOME']:
+        default_cachedir = os.environ['XDG_CACHE_HOME'] + '/ranger'
+    else:
+        default_cachedir = CACHEDIR
+
     parser = OptionParser(usage=USAGE, version=VERSION)
 
     parser.add_option('-d', '--debug', action='store_true',
@@ -232,6 +236,7 @@ def parse_arguments():
     options, positional = parser.parse_args()
     arg = OpenStruct(options.__dict__, targets=positional)
     arg.confdir = expanduser(arg.confdir)
+    arg.cachedir = expanduser(default_cachedir)
 
     if arg.fail_unless_cd: # COMPAT
         sys.stderr.write("Warning: The option --fail-unless-cd is deprecated.\n"