From 2e42090a0d4bade9c1fe37daf8d73c0e7dab2194 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 19 Aug 2010 11:35:32 -0600 Subject: [PATCH] Linux environment: Use atemporary dir as the config directory if write access to the normal config directory is unavailable. Can be overriden by using the CALIBRE_CONFIG_DIRECTORY environment variable --- src/calibre/constants.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/calibre/constants.py b/src/calibre/constants.py index f8d6253912..b78e28be03 100644 --- a/src/calibre/constants.py +++ b/src/calibre/constants.py @@ -98,5 +98,16 @@ elif isosx: else: bdir = os.path.abspath(os.path.expanduser(os.environ.get('XDG_CONFIG_HOME', '~/.config'))) config_dir = os.path.join(bdir, 'calibre') + if not os.access(config_dir, os.W_OK): + print 'No write acces to', config_dir, 'using a temporary dir instead' + import tempfile, atexit + config_dir = tempfile.mkdtemp(prefix='calibre-config-') + def cleanup_cdir(): + try: + import shutil + shutil.rmtree(config_dir) + except: + pass + atexit.register(cleanup_cdir) # }}}