diff options
author | Jon Anderson <jon.david.anderson@gmail.com> | 2018-01-21 01:19:41 -0800 |
---|---|---|
committer | Jon Anderson <jon.david.anderson@gmail.com> | 2018-01-27 15:50:54 -0800 |
commit | 8e24016afb0c12cfb181dbec11ccbaa5986cd9e9 (patch) | |
tree | 55757bdcd4ee339c97aa87f49d450311a7993bf8 | |
parent | a410d09312402d158322f324715d16a9f08caa5f (diff) | |
download | ranger-8e24016afb0c12cfb181dbec11ccbaa5986cd9e9.tar.gz |
Added except catching for Python2.
When reading a file for which Ranger doesn't have permissions, Python3 throws an OSError. Python2 on the other hand throws a IOError, which wasn't being caught and caused Ranger to crash. IOError was added to catch statements for this reason.
-rw-r--r-- | ranger/container/file.py | 3 | ||||
-rw-r--r-- | ranger/core/actions.py | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/ranger/container/file.py b/ranger/container/file.py index d2daa169..6450cfe6 100644 --- a/ranger/container/file.py +++ b/ranger/container/file.py @@ -57,7 +57,8 @@ class File(FileSystemObject): try: with open(self.path, 'rb') as fobj: self._firstbytes = set(fobj.read(N_FIRST_BYTES)) - except OSError: + # IOError for Python2, OSError for Python3 + except (IOError, OSError): return None return self._firstbytes diff --git a/ranger/core/actions.py b/ranger/core/actions.py index 0298af19..aef0d205 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -978,7 +978,8 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m if not self.settings.preview_script or not self.settings.use_preview_script: try: return codecs.open(path, 'r', errors='ignore') - except OSError: + # IOError for Python2, OSError for Python3 + except (IOError, OSError): return None # self.previews is a 2 dimensional dict: |