fix crash in sha encode of previews #139

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@nathantypanski
Contributor

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'

In the example above, I'm doing something ugly (navigating procfs for a PID with ranger), but it still shouldn't be crashing.

This solves that by checking at the beginning of get_preview() that
file.realpath is not None, and returning early if it is None.

@nathantypanski nathantypanski 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.
120ac27
@hut
Member
hut commented Jun 11, 2014

Thanks :)

@hut hut closed this Jun 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment