aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQyriad <qyriad@qyriad.me>2024-05-22 21:17:46 +0000
committerGerrit Code Review <gerrit@lix-systems>2024-05-22 21:17:46 +0000
commit06c1375e52926be4455762ece825589fda86c942 (patch)
treef364c8276fcc80fe98dc9ff43be3c998fc0e1c57
parentdcc7ea54986e0712666b15b502b6f89dd42b000c (diff)
parent6881476232df9979faf1fe0ef5db0ce6ffde77de (diff)
Merge "libfetchers: fallback to memory SQLite if fs IO fails" into main
-rw-r--r--src/libfetchers/cache.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/libfetchers/cache.cc b/src/libfetchers/cache.cc
index 0c8ecac9d..672e1e0bc 100644
--- a/src/libfetchers/cache.cc
+++ b/src/libfetchers/cache.cc
@@ -34,7 +34,16 @@ struct CacheImpl : Cache
auto state(_state.lock());
auto dbPath = getCacheDir() + "/nix/fetcher-cache-v1.sqlite";
- createDirs(dirOf(dbPath));
+ // It would be silly to fail fetcher operations if e.g. the user has no
+ // XDG_CACHE_HOME and their HOME directory doesn't exist.
+ // We'll warn the user if that happens, but fallback to an in-memory
+ // backend for the SQLite database.
+ try {
+ createDirs(dirOf(dbPath));
+ } catch (SysError const & ex) {
+ warn("ignoring error initializing Lix fetcher cache: %s", ex.what());
+ dbPath = ":memory:";
+ }
state->db = SQLite(dbPath);
state->db.isCache();