summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorNathan Typanski <ntypanski@gmail.com>2014-06-10 21:02:39 -0400
committerhut <hut@lepus.uberspace.de>2014-06-11 03:53:09 +0200
commit8061eb4c7003acdc1f2ec5ab26c2ec32913e2d09 (patch)
treef105a86867edd3357766a540868fba2a5d827995
parentdb2bdb28fe42d5ef9ef1aa6a27a56f3a56b993ad (diff)
downloadranger-8061eb4c7003acdc1f2ec5ab26c2ec32913e2d09.tar.gz
fix crash in sha encode of previews
When opening certain filetypes, for which Ranger can't render a preview
(they appear as 0 bytes), Ranger will crash on the sha1_encode:

    Traceback (most recent call last):
    File "~/ranger/ranger/core/main.py", line 139, in main
        cacheimg = os.path.join(ranger.CACHEDIR, self.sha1_encode(path))
    File "~/ranger/ranger/core/actions.py", line 821, in sha1_encode
        sha1(path.encode('utf-8')).hexdigest()) + '.jpg'
    AttributeError: 'NoneType' object has no attribute 'encode'

This solves that by checking at the beginning of get_preview() that
`file.realpath` is not None, and returning early if it is None.
-rw-r--r--ranger/core/actions.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index ea4b54eb..f6c41447 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -828,6 +828,9 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
         pager = self.ui.get_pager()
         path = file.realpath
 
+        if not path:
+            return None
+
         if self.settings.preview_images and file.image:
             pager.set_image(path)
             return None