]> git.notmuchmail.org Git - notmuch/blobdiff - lib/open.cc
lib/open: support XDG_DATA_HOME as a fallback database location.
[notmuch] / lib / open.cc
index 0dfd295f2e8b8da1166cd0e3184789ccef5d0510..25691a8ac6df76de11ad024d701d474d393cdae9 100644 (file)
@@ -181,6 +181,7 @@ _choose_database_path (void *ctx,
                       const char *profile,
                       GKeyFile **key_file,
                       const char **database_path,
+                      bool *split,
                       char **message)
 {
     notmuch_status_t status;
@@ -203,6 +204,11 @@ _choose_database_path (void *ctx,
        }
     }
 
+    if (! *database_path) {
+       *database_path = _xdg_dir (ctx, "XDG_DATA_HOME", ".local/share", profile);
+       *split = true;
+    }
+
     if (*database_path == NULL) {
        *message = strdup ("Error: Cannot open a database for a NULL path.\n");
        return NOTMUCH_STATUS_NULL_POINTER;
@@ -462,6 +468,7 @@ notmuch_database_open_with_config (const char *database_path,
     notmuch_database_t *notmuch = NULL;
     char *message = NULL;
     GKeyFile *key_file = NULL;
+    bool split = false;
 
     _init_libs ();
 
@@ -471,7 +478,8 @@ notmuch_database_open_with_config (const char *database_path,
        goto DONE;
     }
 
-    if ((status = _choose_database_path (local, config_path, profile, &key_file, &database_path,
+    if ((status = _choose_database_path (local, config_path, profile,
+                                        &key_file, &database_path, &split,
                                         &message)))
        goto DONE;
 
@@ -563,7 +571,8 @@ notmuch_database_create_with_config (const char *database_path,
     _init_libs ();
 
     if ((status = _choose_database_path (local, config_path, profile,
-                                        &key_file, &database_path, &message)))
+                                        &key_file, &database_path, &split,
+                                        &message)))
        goto DONE;
 
     status = _db_dir_exists (database_path, &message);