diff options
author | toonn <toonn@toonn.io> | 2020-12-31 15:44:21 +0100 |
---|---|---|
committer | toonn <toonn@toonn.io> | 2020-12-31 19:02:56 +0100 |
commit | 0e02abbe5b8f218f6d429be44759322dc086bca9 (patch) | |
tree | 085ed7e56774183b1cd552c56edbd239894842f0 /ranger | |
parent | 92d7079f523bb62b4fa28cd79077c0df99829025 (diff) | |
download | ranger-0e02abbe5b8f218f6d429be44759322dc086bca9.tar.gz |
Report errors if tag file does not exist
A non-existent tag file leads to an opaque crash without indication to the user of what went wrong as in #2200. These errors are now reported through ranger's notify mechanism. The tag file is no longer created conditionally on `__init__`, only upon saving tags. This changes the behavior somewhat in that an empty "tagged" file should never be created.
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/container/tags.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/ranger/container/tags.py b/ranger/container/tags.py index 50d5ff72..d73b1cf1 100644 --- a/ranger/container/tags.py +++ b/ranger/container/tags.py @@ -13,16 +13,17 @@ from ranger import PY3 ALLOWED_KEYS = string.ascii_letters + string.digits + string.punctuation -class Tags(object): +class Tags(FileManagerAware): default_tag = '*' def __init__(self, filename): + # COMPAT: The intent is to get abspath/normpath's behavior of + # collapsing `symlink/..`, abspath is retained for historical reasons + # because the documentation states its behavior isn't necessarily in + # line with normpath's. self._filename = realpath(abspath(expanduser(filename))) - if isdir(dirname(self._filename)) and not exists(self._filename): - open(self._filename, 'w') - self.sync() def __contains__(self, item): @@ -71,8 +72,11 @@ class Tags(object): fobj = open(self._filename, 'r', errors='replace') else: fobj = open(self._filename, 'r') - except OSError: - pass + except OSError as err: + if exists(self._filename): + self.fm.notify(err, bad=True) + else: + self.tags = dict() else: self.tags = self._parse(fobj) fobj.close() @@ -80,8 +84,8 @@ class Tags(object): def dump(self): try: fobj = open(self._filename, 'w') - except OSError: - pass + except OSError as err: + self.fm.notify(err, bad=True) else: self._compile(fobj) fobj.close() |