[RFC PATCH 05/14] new: use new URL-based filenames for messages

Ethan Glasser-Camp ethan.glasser.camp at gmail.com
Mon Jun 25 13:51:48 PDT 2012


This commit breaks a bunch of tests; fixes follow.

Signed-off-by: Ethan Glasser-Camp <ethan at betacantrips.com>
---
 notmuch-new.c |   27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index 938ae29..1f11b2c 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -287,7 +287,7 @@ add_files (notmuch_database_t *notmuch,
 {
     DIR *dir = NULL;
     struct dirent *entry = NULL;
-    char *next = NULL;
+    char *next = NULL, *path_uri = NULL;
     time_t fs_mtime, db_mtime;
     notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
     notmuch_message_t *message = NULL;
@@ -315,7 +315,16 @@ add_files (notmuch_database_t *notmuch,
 
     fs_mtime = st.st_mtime;
 
-    status = notmuch_database_get_directory (notmuch, path, &directory);
+    /* maildir URIs should never have a hostname component, but
+     * uriparser doesn't parse paths correctly if they start with //,
+     * as in scheme://host//path.
+     */
+    if (path[0] == '/')
+	path_uri = talloc_asprintf (notmuch, "maildir://%s", path);
+    else
+	path_uri = talloc_asprintf (notmuch, "maildir:///%s", path);
+
+    status = notmuch_database_get_directory (notmuch, path_uri, &directory);
     if (status) {
 	ret = status;
 	goto DONE;
@@ -423,7 +432,7 @@ add_files (notmuch_database_t *notmuch,
 	       strcmp (notmuch_filenames_get (db_files), entry->d_name) < 0)
 	{
 	    char *absolute = talloc_asprintf (state->removed_files,
-					      "%s/%s", path,
+					      "%s/%s", path_uri,
 					      notmuch_filenames_get (db_files));
 
 	    _filename_list_add (state->removed_files, absolute);
@@ -439,7 +448,7 @@ add_files (notmuch_database_t *notmuch,
 	    if (strcmp (filename, entry->d_name) < 0)
 	    {
 		char *absolute = talloc_asprintf (state->removed_directories,
-						  "%s/%s", path, filename);
+						  "%s/%s", path_uri, filename);
 
 		_filename_list_add (state->removed_directories, absolute);
 	    }
@@ -467,7 +476,7 @@ add_files (notmuch_database_t *notmuch,
 
 	/* We're now looking at a regular file that doesn't yet exist
 	 * in the database, so add it. */
-	next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
+	next = talloc_asprintf (notmuch, "%s/%s", path_uri, entry->d_name);
 
 	state->processed_files++;
 
@@ -559,7 +568,7 @@ add_files (notmuch_database_t *notmuch,
     while (notmuch_filenames_valid (db_files))
     {
 	char *absolute = talloc_asprintf (state->removed_files,
-					  "%s/%s", path,
+					  "%s/%s", path_uri,
 					  notmuch_filenames_get (db_files));
 
 	_filename_list_add (state->removed_files, absolute);
@@ -570,7 +579,7 @@ add_files (notmuch_database_t *notmuch,
     while (notmuch_filenames_valid (db_subdirs))
     {
 	char *absolute = talloc_asprintf (state->removed_directories,
-					  "%s/%s", path,
+					  "%s/%s", path_uri,
 					  notmuch_filenames_get (db_subdirs));
 
 	_filename_list_add (state->removed_directories, absolute);
@@ -584,9 +593,11 @@ add_files (notmuch_database_t *notmuch,
      * same second.  This may lead to unnecessary re-scans, but it
      * avoids overlooking messages. */
     if (fs_mtime != stat_time)
-	_filename_list_add (state->directory_mtimes, path)->mtime = fs_mtime;
+	_filename_list_add (state->directory_mtimes, path_uri)->mtime = fs_mtime;
 
   DONE:
+    if (path_uri)
+	talloc_free (path_uri);
     if (next)
 	talloc_free (next);
     if (dir)
-- 
1.7.9.5



More information about the notmuch mailing list