]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-config.c
test: Test upgrade to ghost messages feature
[notmuch] / notmuch-config.c
index 88831e278f9fbf10b2d30eccf81a44a3052bfc26..a564bcae362f6b0b9304ade15e580faa67f84437 100644 (file)
@@ -283,16 +283,22 @@ notmuch_config_open (void *ctx,
                                     G_KEY_FILE_KEEP_COMMENTS,
                                     &error))
     {
-       /* If create_new is true, then the caller is prepared for a
-        * default configuration file in the case of FILE NOT
-        * FOUND. Otherwise, any read failure is an error.
-        */
-       if (create_new &&
-           error->domain == G_FILE_ERROR &&
-           error->code == G_FILE_ERROR_NOENT)
-       {
-           g_error_free (error);
-           config->is_new = TRUE;
+       if (error->domain == G_FILE_ERROR && error->code == G_FILE_ERROR_NOENT) {
+           /* If create_new is true, then the caller is prepared for a
+            * default configuration file in the case of FILE NOT
+            * FOUND.
+            */
+           if (create_new) {
+               g_error_free (error);
+               config->is_new = TRUE;
+           } else {
+               fprintf (stderr, "Configuration file %s not found.\n"
+                        "Try running 'notmuch setup' to create a configuration.\n",
+                        config->filename);
+               talloc_free (config);
+               g_error_free (error);
+               return NULL;
+           }
        }
        else
        {
@@ -324,7 +330,9 @@ notmuch_config_open (void *ctx,
 
     if (notmuch_config_get_database_path (config) == NULL) {
        char *path = getenv ("MAILDIR");
-       if (! path)
+       if (path)
+           path = talloc_strdup (config, path);
+       else
            path = talloc_asprintf (config, "%s/mail",
                                    getenv ("HOME"));
        notmuch_config_set_database_path (config, path);
@@ -333,7 +341,9 @@ notmuch_config_open (void *ctx,
 
     if (notmuch_config_get_user_name (config) == NULL) {
        char *name = getenv ("NAME");
-       if (! name)
+       if (name)
+           name = talloc_strdup (config, name);
+       else
            name = get_name_from_passwd_file (config);
        notmuch_config_set_user_name (config, name);
        talloc_free (name);