From 6f0a59c696671c98658e0d8896bb2e3b90cd3392 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 18 Nov 2018 20:02:55 +0530 Subject: [PATCH] If a permission error occurs creating the kitty config directory use a temp dir as the config directory. Fixes #1152 --- kitty/constants.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kitty/constants.py b/kitty/constants.py index eef92db97..1507cc76d 100644 --- a/kitty/constants.py +++ b/kitty/constants.py @@ -7,7 +7,6 @@ import pwd import sys from collections import namedtuple - appname = 'kitty' version = (0, 12, 3) str_version = '.'.join(map(str, version)) @@ -61,6 +60,18 @@ def _get_config_dir(): os.makedirs(ans, exist_ok=True) except FileExistsError: raise SystemExit('A file {} already exists. It must be a directory, not a file.'.format(ans)) + except PermissionError: + import tempfile + import atexit + ans = tempfile.mkdtemp(prefix='kitty-conf-') + + def cleanup(): + import shutil + try: + shutil.rmtree(ans) + except Exception: + pass + atexit.register(cleanup) return ans