summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmjith Ramanujam <amjith@netflix.com>2024-02-18 20:23:13 -0800
committerAmjith Ramanujam <amjith@netflix.com>2024-02-18 20:23:13 -0800
commit8296335dbb951bae27f21fda96d8d498546e6702 (patch)
tree9dc42ca1a33d49aa75d38da05b591b7e9edaf193
parentb183f86e45dc8b69797e09227769d99245ab1d0a (diff)
Do not crash if ~/.config/litecli is not writeable.
-rw-r--r--litecli/config.py6
-rw-r--r--litecli/main.py6
2 files changed, 10 insertions, 2 deletions
diff --git a/litecli/config.py b/litecli/config.py
index 1c7fb25..55d3e32 100644
--- a/litecli/config.py
+++ b/litecli/config.py
@@ -57,6 +57,10 @@ def get_config(liteclirc_file=None):
liteclirc_file = liteclirc_file or "%sconfig" % config_location()
default_config = os.path.join(package_root, "liteclirc")
- write_default_config(default_config, liteclirc_file)
+ try:
+ write_default_config(default_config, liteclirc_file)
+ except OSError:
+ # If we can't write to the config file, just use the default config
+ return load_config(default_config)
return load_config(liteclirc_file, default_config)
diff --git a/litecli/main.py b/litecli/main.py
index e608da7..268ede2 100644
--- a/litecli/main.py
+++ b/litecli/main.py
@@ -239,7 +239,11 @@ class LiteCli(object):
log_file = self.config["main"]["log_file"]
if log_file == "default":
log_file = config_location() + "log"
- ensure_dir_exists(log_file)
+ try:
+ ensure_dir_exists(log_file)
+ except OSError:
+ # Unable to create log file, log to temp directory instead.
+ log_file = "/tmp/litecli.log"
log_level = self.config["main"]["log_level"]