summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorGermainZ <germanosz@gmail.com>2014-03-09 22:14:46 +0200
committerGermainZ <germanosz@gmail.com>2014-03-09 22:14:46 +0200
commit91daf58b56c7b84361f6be52097b753e737f3002 (patch)
tree57e0d0c8f975bee77139fa4ecc55f0b2f1323f37 /ranger
parentc2ec5e1b34fa702879ff73ef8941cf416edf5402 (diff)
downloadranger-91daf58b56c7b84361f6be52097b753e737f3002.tar.gz
Python2 fix for utf-8 characters in file paths
Diffstat (limited to 'ranger')
-rw-r--r--ranger/core/actions.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 9f20adbb..a3497902 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -12,6 +12,7 @@ from os import link, symlink, getcwd, listdir, stat
 from inspect import cleandoc
 from stat import S_IEXEC
 from hashlib import sha1
+from sys import version_info
 
 import ranger
 from ranger.ext.direction import Direction
@@ -799,6 +800,13 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
         except:
             return False
 
+    if version_info[0] == 3:
+        def sha1_encode(self, path):
+            return os.path.join(ranger.CACHEDIR, sha1(path.encode('utf-8')).hexdigest())
+    else:
+        def sha1_encode(self, path):
+            return os.path.join(ranger.CACHEDIR, sha1(path).hexdigest())
+
     def get_preview(self, file, width, height):
         pager = self.ui.get_pager()
         path = file.realpath
@@ -842,7 +850,7 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 
                 data['loading'] = True
 
-                cacheimg = os.path.join(ranger.CACHEDIR, sha1(path.encode()).hexdigest() + '.jpg')
+                cacheimg = os.path.join(ranger.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