Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id C71D7431FD7 for ; Tue, 23 Feb 2010 18:28:35 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.351 X-Spam-Level: X-Spam-Status: No, score=-2.351 tagged_above=-999 required=5 tests=[AWL=0.248, BAYES_00=-2.599] autolearn=ham Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id y9CI-WdAINbz for ; Tue, 23 Feb 2010 18:28:35 -0800 (PST) Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU [18.9.25.15]) by olra.theworths.org (Postfix) with ESMTP id D880D431FCF for ; Tue, 23 Feb 2010 18:28:30 -0800 (PST) X-AuditID: 1209190f-b7c94ae00000096e-5d-4b848d92b612 Received: from mailhub-auth-2.mit.edu (MAILHUB-AUTH-2.MIT.EDU [18.7.62.36]) by dmz-mailsec-scanner-4.mit.edu (Symantec Brightmail Gateway) with SMTP id FC.CF.02414.29D848B4; Tue, 23 Feb 2010 21:23:14 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id o1O2NEZU008876; Tue, 23 Feb 2010 21:23:14 -0500 Received: from localhost.localdomain (ET-NINETY-THREE.MIT.EDU [18.208.1.93]) (authenticated bits=0) (User authenticated as davidben@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id o1O2NTiu021532 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 23 Feb 2010 21:23:35 -0500 (EST) From: David Benjamin To: notmuch@notmuchmail.org Date: Tue, 23 Feb 2010 21:23:02 -0500 Message-Id: <1266978183-19698-4-git-send-email-davidben@mit.edu> X-Mailer: git-send-email 1.7.0.18.g39b3 In-Reply-To: <1266978183-19698-1-git-send-email-davidben@mit.edu> References: <1266978183-19698-1-git-send-email-davidben@mit.edu> X-Brightmail-Tracker: AAAAARMIvZ4= Subject: [notmuch] [PATCH 3/4] Configure the database separately from mail store X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Feb 2010 02:28:35 -0000 Signed-off-by: David Benjamin --- notmuch-client.h | 7 ++++++ notmuch-config.c | 62 ++++++++++++++++++++++++++++++++++++++++-------------- notmuch-new.c | 14 ++++------- 3 files changed, 58 insertions(+), 25 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index 1a676d2..010fdc7 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -148,6 +148,13 @@ void notmuch_config_set_database_path (notmuch_config_t *config, const char *database_path); +const char * +notmuch_config_get_database_notmuch_path (notmuch_config_t *config); + +void +notmuch_config_set_database_notmuch_path (notmuch_config_t *config, + const char *database_notmuch_path); + notmuch_database_t * notmuch_config_open_database (notmuch_config_t *config, notmuch_database_mode_t mode); diff --git a/notmuch-config.c b/notmuch-config.c index 58a28b1..b20047c 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -58,6 +58,7 @@ struct _notmuch_config { GKeyFile *key_file; char *database_path; + char *database_notmuch_path; char *user_name; char *user_primary_email; char **user_other_email; @@ -151,6 +152,8 @@ get_username_from_passwd_file (void *ctx) * * database_path: $HOME/mail * + * database_notmuch_path: database_path/.notmuch + * * user_name: From /etc/passwd * * user_primary_mail: $EMAIL variable if set, otherwise @@ -195,6 +198,7 @@ notmuch_config_open (void *ctx, config->key_file = g_key_file_new (); config->database_path = NULL; + config->database_notmuch_path = NULL; config->user_name = NULL; config->user_primary_email = NULL; config->user_other_email = NULL; @@ -351,6 +355,45 @@ notmuch_config_set_database_path (notmuch_config_t *config, talloc_free (config->database_path); config->database_path = NULL; + /* In case this path is dynamically generated */ + talloc_free (config->database_notmuch_path); + config->database_notmuch_path = NULL +} + +const char * +notmuch_config_get_database_notmuch_path (notmuch_config_t *config) +{ + const char *path; + char *notmuch_path; + + if (config->database_notmuch_path == NULL) { + notmuch_path = g_key_file_get_string (config->key_file, + "database", "notmuch_path", NULL); + if (notmuch_path) { + config->database_notmuch_path = talloc_strdup (config, notmuch_path); + free (notmuch_path); + } else { + path = notmuch_config_get_database_path (config); + if (path != NULL) { + notmuch_path = talloc_asprintf (config, "%s/%s", + path, ".notmuch"); + config->database_notmuch_path = notmuch_path; + } + } + } + + return config->database_notmuch_path; +} + +void +notmuch_config_set_database_notmuch_path (notmuch_config_t *config, + const char *database_notmuch_path) +{ + g_key_file_set_string (config->key_file, + "database", "notmuch_path", database_notmuch_path); + + talloc_free (config->database_notmuch_path); + config->database_notmuch_path = NULL; } notmuch_database_t * @@ -358,26 +401,13 @@ notmuch_config_open_database (notmuch_config_t *config, notmuch_database_mode_t mode) { const char *path = NULL; - char *db_path = NULL; + const char *notmuch_path = NULL; notmuch_database_t *notmuch = NULL; path = notmuch_config_get_database_path (config); - if (path == NULL) { - fprintf (stderr, "Error: Cannot create a database for a NULL path.\n"); - goto DONE; - } - - if (asprintf (&db_path, "%s/%s", path, ".notmuch") == -1) { - db_path = NULL; - fprintf (stderr, "Out of memory\n"); - goto DONE; - } - - notmuch = notmuch_database_open (path, db_path, mode); + notmuch_path = notmuch_config_get_database_notmuch_path (config); -DONE: - if (db_path) - free(db_path); + notmuch = notmuch_database_open (path, notmuch_path, mode); return notmuch; } diff --git a/notmuch-new.c b/notmuch-new.c index d24dab9..d36edd5 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -713,7 +713,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) int ret = 0; struct stat st; const char *db_path; - char *dot_notmuch_path; + const char *notmuch_path; struct sigaction action; _filename_node_t *f; int renamed_files, removed_files; @@ -737,10 +737,9 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) return 1; db_path = notmuch_config_get_database_path (config); + notmuch_path = notmuch_config_get_database_notmuch_path (config); - dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch"); - - if (stat (dot_notmuch_path, &st)) { + if (stat (notmuch_path, &st)) { int count; count = 0; @@ -749,11 +748,11 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) return 1; printf ("Found %d total files (that's not much mail).\n", count); - notmuch = notmuch_database_create (db_path, dot_notmuch_path); + notmuch = notmuch_database_create (db_path, notmuch_path); add_files_state.total_files = count; } else { notmuch = notmuch_database_open (db_path, - dot_notmuch_path, + notmuch_path, NOTMUCH_DATABASE_MODE_READ_WRITE); if (notmuch == NULL) return 1; @@ -782,9 +781,6 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) action.sa_flags = SA_RESTART; sigaction (SIGINT, &action, NULL); - talloc_free (dot_notmuch_path); - dot_notmuch_path = NULL; - add_files_state.processed_files = 0; add_files_state.added_messages = 0; gettimeofday (&add_files_state.tv_start, NULL); -- 1.7.0.18.g39b3