]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-config.c
test: Test upgrade to ghost messages feature
[notmuch] / notmuch-config.c
index 8d286538c086180ef9c88ef6a00315c95fc67fea..a564bcae362f6b0b9304ade15e580faa67f84437 100644 (file)
@@ -217,9 +217,10 @@ get_username_from_passwd_file (void *ctx)
  *     These default configuration settings are determined as
  *     follows:
  *
- *             database_path:          $HOME/mail
+ *             database_path:          $MAILDIR, otherwise $HOME/mail
  *
- *             user_name:              From /etc/passwd
+ *             user_name:              $NAME variable if set, otherwise
+ *                                     read from /etc/passwd
  *
  *             user_primary_mail:      $EMAIL variable if set, otherwise
  *                                     constructed from the username and
@@ -282,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
        {
@@ -322,14 +329,22 @@ notmuch_config_open (void *ctx,
 
 
     if (notmuch_config_get_database_path (config) == NULL) {
-       char *path = talloc_asprintf (config, "%s/mail",
-                                     getenv ("HOME"));
+       char *path = getenv ("MAILDIR");
+       if (path)
+           path = talloc_strdup (config, path);
+       else
+           path = talloc_asprintf (config, "%s/mail",
+                                   getenv ("HOME"));
        notmuch_config_set_database_path (config, path);
        talloc_free (path);
     }
 
     if (notmuch_config_get_user_name (config) == NULL) {
-       char *name = get_name_from_passwd_file (config);
+       char *name = getenv ("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);
     }
@@ -454,7 +469,7 @@ notmuch_config_save (notmuch_config_t *config)
     }
 
     /* Try not to overwrite symlinks. */
-    filename = realpath (config->filename, NULL);
+    filename = canonicalize_file_name (config->filename);
     if (! filename) {
        if (errno == ENOENT) {
            filename = strdup (config->filename);