diff options
author | Wojciech Siewierski <wojciech@siewierski.eu> | 2020-01-27 21:00:14 +0100 |
---|---|---|
committer | Wojciech Siewierski <wojciech@siewierski.eu> | 2020-01-27 21:00:14 +0100 |
commit | 8af08018f22f0a65ed40c73899a37cfa74b82980 (patch) | |
tree | 72e0a41b84e69595c76c071dc5b6825b8e53a86e | |
parent | 3965e3eeafac8ce44670cfdc25ccc7b5997a3366 (diff) | |
download | ranger-8af08018f22f0a65ed40c73899a37cfa74b82980.tar.gz |
Cleanup the temporary cache directory in the --clean mode
-rw-r--r-- | ranger/core/main.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/ranger/core/main.py b/ranger/core/main.py index 7322a501..16f993cc 100644 --- a/ranger/core/main.py +++ b/ranger/core/main.py @@ -6,8 +6,10 @@ from __future__ import (absolute_import, division, print_function) from logging import getLogger +import atexit import locale import os.path +import shutil import sys import tempfile @@ -337,6 +339,17 @@ def parse_arguments(): args.cachedir = mkdtemp(suffix='.ranger-cache') args.confdir = None args.datadir = None + + @atexit.register + def cleanup_cachedir(): # pylint: disable=unused-variable + try: + shutil.rmtree(args.cachedir) + except Exception as ex: # pylint: disable=broad-except + sys.stderr.write( + "Error during the temporary cache directory cleanup: " + "{}\n".format(ex) + ) + else: args.cachedir = path_init('cachedir') args.confdir = path_init('confdir') |