about summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authortoonn <toonn@toonn.io>2020-07-08 22:24:49 +0200
committertoonn <toonn@toonn.io>2020-07-08 22:24:49 +0200
commit05d2263d770a2a01a2a78aad28f7e48c2615ab27 (patch)
tree76d1b59955d2559d99ae34ae56dd0fb433cf5d34 /ranger
parent01efdae6aa2384ac3e634a89c910659d4624c55c (diff)
parente13536cd38ac86ea66f1fddadf3a9cfa15a1630f (diff)
downloadranger-05d2263d770a2a01a2a78aad28f7e48c2615ab27.tar.gz
Merge branch 'cache-hash'
Diffstat (limited to 'ranger')
-rw-r--r--ranger/core/actions.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index c42312ce..d7ead160 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -1019,11 +1019,12 @@ class Actions(  # pylint: disable=too-many-instance-attributes,too-many-public-m
         return True
 
     @staticmethod
-    def sha512_encode(path):
-        stat_ = stat(path)
-        sha = sha512(stat_.st_dev)
-        sha.update(stat_.st_ino)
-        sha.update(stat_.st_mtime)
+    def sha512_encode(path, inode=None):
+        if inode is None:
+            inode = stat(path).st_ino
+        sha = sha512(
+            "{0}{1}".format(path, str(inode)).encode('utf-8', 'backslashescape')
+        )
         return '{0}.jpg'.format(sha.hexdigest())
 
     def get_preview(self, fobj, width, height):
@@ -1093,9 +1094,13 @@ class Actions(  # pylint: disable=too-many-instance-attributes,too-many-public-m
 
         if not os.path.exists(ranger.args.cachedir):
             os.makedirs(ranger.args.cachedir)
-        cacheimg = os.path.join(ranger.args.cachedir, self.sha512_encode(path))
-        if self.settings.preview_images and \
-                os.path.isfile(cacheimg):
+        fobj.load_if_outdated()
+        cacheimg = os.path.join(
+            ranger.args.cachedir,
+            self.sha512_encode(path, inode=fobj.stat.st_ino)
+        )
+        if (self.settings.preview_images and os.path.isfile(cacheimg)
+                and fobj.stat.st_mtime <= os.path.getmtime(cacheimg)):
             data['foundpreview'] = True
             data['imagepreview'] = True
             pager.set_image(cacheimg)