* [PATCH 0/4] Allow separate database directory from mail store
@ 2010-02-24 2:22 David Benjamin
2010-02-24 2:23 ` [PATCH 1/4] lib/database.cc: Fix function name in comment David Benjamin
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: David Benjamin @ 2010-02-24 2:22 UTC (permalink / raw)
To: notmuch
This patchset separates and makes configurable the database directory from the
mail store. In the code, I have elected to call the former the 'notmuch_path'
as, of the various of names in the source code ('path', 'db_path', etc.), that
was the only one that consistently refers to the .notmuch directory.
If notmuch_path is not configured, the usual location of $MAILSTORE/.notmuch is
used.
The first of the four is an irrelevant little documentation fix that I didn't
think was worth making a new thread for.
David Benjamin (4):
lib/database.cc: Fix function name in comment
Pass separate notmuch_path when opening database
Configure the database separately from mail store
Prompt for database location in notmuch setup
lib/database-private.h | 1 +
lib/database.cc | 30 ++++++++++++------------
lib/notmuch.h | 32 ++++++++++++++++---------
notmuch-client.h | 11 +++++++++
notmuch-config.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++
notmuch-count.c | 4 +-
notmuch-dump.c | 4 +-
notmuch-new.c | 13 ++++------
notmuch-reply.c | 4 +-
notmuch-restore.c | 4 +-
notmuch-search-tags.c | 4 +-
notmuch-search.c | 4 +-
notmuch-setup.c | 9 +++++++
notmuch-show.c | 4 +-
notmuch-tag.c | 4 +-
15 files changed, 136 insertions(+), 51 deletions(-)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/4] lib/database.cc: Fix function name in comment
2010-02-24 2:22 [PATCH 0/4] Allow separate database directory from mail store David Benjamin
@ 2010-02-24 2:23 ` David Benjamin
2010-02-24 2:23 ` [PATCH 2/4] Pass separate notmuch_path when opening database David Benjamin
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: David Benjamin @ 2010-02-24 2:23 UTC (permalink / raw)
To: notmuch
notmuch_message_add_filename has a leading underscore in the name.
Signed-off-by: David Benjamin <davidben@mit.edu>
---
lib/database.cc | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/database.cc b/lib/database.cc
index 2b5b64d..1bb24ec 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -739,7 +739,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
/* Before version 1, each message document had its filename in the
* data field. Copy that into the new format by calling
- * notmuch_message_add_filename.
+ * _notmuch_message_add_filename.
*/
if (version < 1) {
notmuch_query_t *query = notmuch_query_create (notmuch, "");
--
1.7.0.18.g39b3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/4] Pass separate notmuch_path when opening database
2010-02-24 2:22 [PATCH 0/4] Allow separate database directory from mail store David Benjamin
2010-02-24 2:23 ` [PATCH 1/4] lib/database.cc: Fix function name in comment David Benjamin
@ 2010-02-24 2:23 ` David Benjamin
2010-02-24 2:23 ` [PATCH 3/4] Configure the database separately from mail store David Benjamin
2010-02-24 2:23 ` [PATCH 4/4] Prompt for database location in notmuch setup David Benjamin
3 siblings, 0 replies; 6+ messages in thread
From: David Benjamin @ 2010-02-24 2:23 UTC (permalink / raw)
To: notmuch
Avoid hard-coding $MAILSTORE/.notmuch in the database layer.
Signed-off-by: David Benjamin <davidben@mit.edu>
---
lib/database-private.h | 1 +
lib/database.cc | 28 ++++++++++++++--------------
lib/notmuch.h | 32 ++++++++++++++++++++------------
notmuch-client.h | 4 ++++
notmuch-config.c | 29 +++++++++++++++++++++++++++++
notmuch-count.c | 4 ++--
notmuch-dump.c | 4 ++--
notmuch-new.c | 3 ++-
notmuch-reply.c | 4 ++--
notmuch-restore.c | 4 ++--
notmuch-search-tags.c | 4 ++--
notmuch-search.c | 4 ++--
notmuch-show.c | 4 ++--
notmuch-tag.c | 4 ++--
14 files changed, 86 insertions(+), 43 deletions(-)
diff --git a/lib/database-private.h b/lib/database-private.h
index 41918d7..59ed117 100644
--- a/lib/database-private.h
+++ b/lib/database-private.h
@@ -38,6 +38,7 @@ struct _notmuch_database {
notmuch_bool_t exception_reported;
char *path;
+ char *notmuch_path;
notmuch_bool_t needs_upgrade;
notmuch_database_mode_t mode;
diff --git a/lib/database.cc b/lib/database.cc
index 1bb24ec..f54fbd1 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -437,14 +437,14 @@ parse_references (void *ctx,
}
notmuch_database_t *
-notmuch_database_create (const char *path)
+notmuch_database_create (const char *path,
+ const char *notmuch_path)
{
notmuch_database_t *notmuch = NULL;
- char *notmuch_path = NULL;
struct stat st;
int err;
- if (path == NULL) {
+ if (path == NULL || notmuch_path == NULL) {
fprintf (stderr, "Error: Cannot create a database for a NULL path.\n");
goto DONE;
}
@@ -462,8 +462,6 @@ notmuch_database_create (const char *path)
goto DONE;
}
- notmuch_path = talloc_asprintf (NULL, "%s/%s", path, ".notmuch");
-
err = mkdir (notmuch_path, 0755);
if (err) {
@@ -473,13 +471,11 @@ notmuch_database_create (const char *path)
}
notmuch = notmuch_database_open (path,
+ notmuch_path,
NOTMUCH_DATABASE_MODE_READ_WRITE);
notmuch_database_upgrade (notmuch, NULL, NULL);
DONE:
- if (notmuch_path)
- talloc_free (notmuch_path);
-
return notmuch;
}
@@ -496,17 +492,17 @@ _notmuch_database_ensure_writable (notmuch_database_t *notmuch)
notmuch_database_t *
notmuch_database_open (const char *path,
+ const char *notmuch_path,
notmuch_database_mode_t mode)
{
notmuch_database_t *notmuch = NULL;
- char *notmuch_path = NULL, *xapian_path = NULL;
+ char *xapian_path = NULL;
struct stat st;
int err;
unsigned int i, version;
- if (asprintf (¬much_path, "%s/%s", path, ".notmuch") == -1) {
- notmuch_path = NULL;
- fprintf (stderr, "Out of memory\n");
+ if (path == NULL || notmuch_path == NULL) {
+ fprintf (stderr, "Error: Cannot create a database for a NULL path.\n");
goto DONE;
}
@@ -611,8 +607,6 @@ notmuch_database_open (const char *path,
}
DONE:
- if (notmuch_path)
- free (notmuch_path);
if (xapian_path)
free (xapian_path);
@@ -645,6 +639,12 @@ notmuch_database_get_path (notmuch_database_t *notmuch)
return notmuch->path;
}
+const char *
+notmuch_database_get_notmuch_path (notmuch_database_t *notmuch)
+{
+ return notmuch->notmuch_path;
+}
+
unsigned int
notmuch_database_get_version (notmuch_database_t *notmuch)
{
diff --git a/lib/notmuch.h b/lib/notmuch.h
index d3e50a7..943c297 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -120,12 +120,12 @@ typedef struct _notmuch_tags notmuch_tags_t;
typedef struct _notmuch_directory notmuch_directory_t;
typedef struct _notmuch_filenames notmuch_filenames_t;
-/* Create a new, empty notmuch database located at 'path'.
+/* Create a new, empty notmuch database located at 'notmuch_path',
+ * indexing mail store 'path'
*
* The path should be a top-level directory to a collection of
* plain-text email messages (one message per file). This call will
- * create a new ".notmuch" directory within 'path' where notmuch will
- * store its data.
+ * create directory 'notmuch_path' where notmuch will store its data.
*
* After a successful call to notmuch_database_create, the returned
* database will be open so the caller should call
@@ -140,7 +140,8 @@ typedef struct _notmuch_filenames notmuch_filenames_t;
* an error message on stderr).
*/
notmuch_database_t *
-notmuch_database_create (const char *path);
+notmuch_database_create (const char *path,
+ const char *notmuch_path);
typedef enum {
NOTMUCH_DATABASE_MODE_READ_ONLY = 0,
@@ -150,16 +151,15 @@ typedef enum {
/* XXX: I think I'd like this to take an extra argument of
* notmuch_status_t* for returning a status value on failure. */
-/* Open an existing notmuch database located at 'path'.
+/* Open an existing notmuch database located at 'notmuch_path' with
+ * mail store rooted at 'path'
*
* The database should have been created at some time in the past,
* (not necessarily by this process), by calling
- * notmuch_database_create with 'path'. By default the database should be
- * opened for reading only. In order to write to the database you need to
- * pass the NOTMUCH_DATABASE_MODE_WRITABLE mode.
- *
- * An existing notmuch database can be identified by the presence of a
- * directory named ".notmuch" below 'path'.
+ * notmuch_database_create with 'path' and 'notmuch_path'. By default
+ * the database should be opened for reading only. In order to write
+ * to the database you need to pass the NOTMUCH_DATABASE_MODE_WRITABLE
+ * mode.
*
* The caller should call notmuch_database_close when finished with
* this database.
@@ -169,6 +169,7 @@ typedef enum {
*/
notmuch_database_t *
notmuch_database_open (const char *path,
+ const char *notmuch_path,
notmuch_database_mode_t mode);
/* Close the given notmuch database, freeing all associated
@@ -176,13 +177,20 @@ notmuch_database_open (const char *path,
void
notmuch_database_close (notmuch_database_t *database);
-/* Return the database path of the given database.
+/* Return the mail store path of the given database.
*
* The return value is a string owned by notmuch so should not be
* modified nor freed by the caller. */
const char *
notmuch_database_get_path (notmuch_database_t *database);
+/* Return the database path of the given database.
+ *
+ * The return value is a string owned by notmuch so should not be
+ * modified nor freed by the caller. */
+const char *
+notmuch_database_get_notmuch_path (notmuch_database_t *database);
+
/* Return the database format version of the given database. */
unsigned int
notmuch_database_get_version (notmuch_database_t *database);
diff --git a/notmuch-client.h b/notmuch-client.h
index c80b39c..1a676d2 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -148,6 +148,10 @@ void
notmuch_config_set_database_path (notmuch_config_t *config,
const char *database_path);
+notmuch_database_t *
+notmuch_config_open_database (notmuch_config_t *config,
+ notmuch_database_mode_t mode);
+
const char *
notmuch_config_get_user_name (notmuch_config_t *config);
diff --git a/notmuch-config.c b/notmuch-config.c
index 95430db..58a28b1 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -353,6 +353,35 @@ notmuch_config_set_database_path (notmuch_config_t *config,
config->database_path = NULL;
}
+notmuch_database_t *
+notmuch_config_open_database (notmuch_config_t *config,
+ notmuch_database_mode_t mode)
+{
+ const char *path = NULL;
+ char *db_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);
+
+DONE:
+ if (db_path)
+ free(db_path);
+
+ return notmuch;
+}
+
const char *
notmuch_config_get_user_name (notmuch_config_t *config)
{
diff --git a/notmuch-count.c b/notmuch-count.c
index 77aa433..8d077eb 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -80,8 +80,8 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
if (config == NULL)
return 1;
- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
- NOTMUCH_DATABASE_MODE_READ_ONLY);
+ notmuch = notmuch_config_open_database (config,
+ NOTMUCH_DATABASE_MODE_READ_ONLY);
if (notmuch == NULL)
return 1;
diff --git a/notmuch-dump.c b/notmuch-dump.c
index ea326bb..a051fd4 100644
--- a/notmuch-dump.c
+++ b/notmuch-dump.c
@@ -35,8 +35,8 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
if (config == NULL)
return 1;
- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
- NOTMUCH_DATABASE_MODE_READ_ONLY);
+ notmuch = notmuch_config_open_database (config,
+ NOTMUCH_DATABASE_MODE_READ_ONLY);
if (notmuch == NULL)
return 1;
diff --git a/notmuch-new.c b/notmuch-new.c
index f25c71f..d24dab9 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -749,10 +749,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);
+ notmuch = notmuch_database_create (db_path, dot_notmuch_path);
add_files_state.total_files = count;
} else {
notmuch = notmuch_database_open (db_path,
+ dot_notmuch_path,
NOTMUCH_DATABASE_MODE_READ_WRITE);
if (notmuch == NULL)
return 1;
diff --git a/notmuch-reply.c b/notmuch-reply.c
index 98f6442..10734bc 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -467,8 +467,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
return 1;
}
- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
- NOTMUCH_DATABASE_MODE_READ_ONLY);
+ notmuch = notmuch_config_open_database (config,
+ NOTMUCH_DATABASE_MODE_READ_ONLY);
if (notmuch == NULL)
return 1;
diff --git a/notmuch-restore.c b/notmuch-restore.c
index 53ce254..d495b4f 100644
--- a/notmuch-restore.c
+++ b/notmuch-restore.c
@@ -36,8 +36,8 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
if (config == NULL)
return 1;
- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
- NOTMUCH_DATABASE_MODE_READ_WRITE);
+ notmuch = notmuch_config_open_database (config,
+ NOTMUCH_DATABASE_MODE_READ_WRITE);
if (notmuch == NULL)
return 1;
diff --git a/notmuch-search-tags.c b/notmuch-search-tags.c
index 7a1305e..1ddbb94 100644
--- a/notmuch-search-tags.c
+++ b/notmuch-search-tags.c
@@ -51,8 +51,8 @@ notmuch_search_tags_command (void *ctx, int argc, char *argv[])
goto error;
}
- db = notmuch_database_open (notmuch_config_get_database_path (config),
- NOTMUCH_DATABASE_MODE_READ_ONLY);
+ db = notmuch_config_open_database (config,
+ NOTMUCH_DATABASE_MODE_READ_ONLY);
if (db == NULL) {
goto error;
}
diff --git a/notmuch-search.c b/notmuch-search.c
index 25dd6eb..2b65e87 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -244,8 +244,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
if (config == NULL)
return 1;
- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
- NOTMUCH_DATABASE_MODE_READ_ONLY);
+ notmuch = notmuch_config_open_database (config,
+ NOTMUCH_DATABASE_MODE_READ_ONLY);
if (notmuch == NULL)
return 1;
diff --git a/notmuch-show.c b/notmuch-show.c
index 1a1d601..88124dc 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -446,8 +446,8 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
return 1;
}
- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
- NOTMUCH_DATABASE_MODE_READ_ONLY);
+ notmuch = notmuch_config_open_database (config,
+ NOTMUCH_DATABASE_MODE_READ_ONLY);
if (notmuch == NULL)
return 1;
diff --git a/notmuch-tag.c b/notmuch-tag.c
index 00588a1..1deff1a 100644
--- a/notmuch-tag.c
+++ b/notmuch-tag.c
@@ -96,8 +96,8 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))
if (config == NULL)
return 1;
- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
- NOTMUCH_DATABASE_MODE_READ_WRITE);
+ notmuch = notmuch_config_open_database (config,
+ NOTMUCH_DATABASE_MODE_READ_WRITE);
if (notmuch == NULL)
return 1;
--
1.7.0.18.g39b3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/4] Configure the database separately from mail store
2010-02-24 2:22 [PATCH 0/4] Allow separate database directory from mail store David Benjamin
2010-02-24 2:23 ` [PATCH 1/4] lib/database.cc: Fix function name in comment David Benjamin
2010-02-24 2:23 ` [PATCH 2/4] Pass separate notmuch_path when opening database David Benjamin
@ 2010-02-24 2:23 ` David Benjamin
2010-02-26 23:06 ` [PATCH v2 " David Benjamin
2010-02-24 2:23 ` [PATCH 4/4] Prompt for database location in notmuch setup David Benjamin
3 siblings, 1 reply; 6+ messages in thread
From: David Benjamin @ 2010-02-24 2:23 UTC (permalink / raw)
To: notmuch
Signed-off-by: David Benjamin <davidben@mit.edu>
---
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/4] Prompt for database location in notmuch setup
2010-02-24 2:22 [PATCH 0/4] Allow separate database directory from mail store David Benjamin
` (2 preceding siblings ...)
2010-02-24 2:23 ` [PATCH 3/4] Configure the database separately from mail store David Benjamin
@ 2010-02-24 2:23 ` David Benjamin
3 siblings, 0 replies; 6+ messages in thread
From: David Benjamin @ 2010-02-24 2:23 UTC (permalink / raw)
To: notmuch
Signed-off-by: David Benjamin <davidben@mit.edu>
---
notmuch-setup.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/notmuch-setup.c b/notmuch-setup.c
index 622bbaa..e3c8465 100644
--- a/notmuch-setup.c
+++ b/notmuch-setup.c
@@ -159,6 +159,15 @@ notmuch_setup_command (unused (void *ctx),
notmuch_config_set_database_path (config, absolute_path);
}
+ prompt ("Location for notmuch database [%s]: ",
+ notmuch_config_get_database_notmuch_path (config));
+ if (strlen (response)) {
+ const char *absolute_path;
+
+ absolute_path = make_path_absolute (ctx, response);
+ notmuch_config_set_database_notmuch_path (config, absolute_path);
+ }
+
if (! notmuch_config_save (config)) {
if (is_new)
welcome_message_post_setup ();
--
1.7.0.18.g39b3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/4] Configure the database separately from mail store
2010-02-24 2:23 ` [PATCH 3/4] Configure the database separately from mail store David Benjamin
@ 2010-02-26 23:06 ` David Benjamin
0 siblings, 0 replies; 6+ messages in thread
From: David Benjamin @ 2010-02-26 23:06 UTC (permalink / raw)
To: notmuch
Signed-off-by: David Benjamin <davidben@mit.edu>
---
Apparently I never ran the last-minute tweak I did to
notmuch_config_set_database_path. Oops. Oh well, here's the trivially fixed
version.
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..ccae35d 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
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-02-26 23:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-24 2:22 [PATCH 0/4] Allow separate database directory from mail store David Benjamin
2010-02-24 2:23 ` [PATCH 1/4] lib/database.cc: Fix function name in comment David Benjamin
2010-02-24 2:23 ` [PATCH 2/4] Pass separate notmuch_path when opening database David Benjamin
2010-02-24 2:23 ` [PATCH 3/4] Configure the database separately from mail store David Benjamin
2010-02-26 23:06 ` [PATCH v2 " David Benjamin
2010-02-24 2:23 ` [PATCH 4/4] Prompt for database location in notmuch setup David Benjamin
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).