summary refs log tree commit diff stats
path: root/ranger/container/file.py
diff options
context:
space:
mode:
Diffstat (limited to 'ranger/container/file.py')
-rw-r--r--ranger/container/file.py13
1 files changed, 5 insertions, 8 deletions
diff --git a/ranger/container/file.py b/ranger/container/file.py
index e1284c1f..e0b9922c 100644
--- a/ranger/container/file.py
+++ b/ranger/container/file.py
@@ -54,14 +54,11 @@ class File(FileSystemObject):
     def firstbytes(self):
         if self._firstbytes is None:
             try:
-                fobj = open(self.path, 'r')
-                self._firstbytes = fobj.read(N_FIRST_BYTES)
-                fobj.close()
-                return self._firstbytes
-            except Exception:
-                pass
-        else:
-            return self._firstbytes
+                with open(self.path, 'r') as fobj:
+                    self._firstbytes = fobj.read(N_FIRST_BYTES)
+            except OSError:
+                return None
+        return self._firstbytes
 
     def is_binary(self):
         if self.firstbytes and control_characters & set(self.firstbytes):