From 8af08018f22f0a65ed40c73899a37cfa74b82980 Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Mon, 27 Jan 2020 21:00:14 +0100 Subject: Cleanup the temporary cache directory in the --clean mode --- ranger/core/main.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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') -- cgit 1.4.1-2-gfad0