[PATCH v2 3/8] Not all filenames need to be converted to absolute paths

Ethan Glasser-Camp ethan.glasser.camp at gmail.com
Sun Jul 1 09:39:45 PDT 2012


_notmuch_message_ensure_filename_list converts "relative" paths, such
as those stored in Xapian until now, to "absolute" paths. However,
URLs are already absolute, and prepending the database path will just
confuse matters.

Signed-off-by: Ethan Glasser-Camp <ethan at betacantrips.com>
---
 lib/message.cc |   20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index 978de06..235185c 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -21,6 +21,7 @@
 #include "notmuch-private.h"
 #include "database-private.h"
 
+#include <uriparser/Uri.h>
 #include <stdint.h>
 
 #include <gmime/gmime.h>
@@ -682,6 +683,8 @@ _notmuch_message_ensure_filename_list (notmuch_message_t *message)
 	const char *db_path, *directory, *basename, *filename;
 	char *colon, *direntry = NULL;
 	unsigned int directory_id;
+	UriUriA parsed;
+	UriParserStateA parser;
 
 	direntry = node->string;
 
@@ -700,9 +703,20 @@ _notmuch_message_ensure_filename_list (notmuch_message_t *message)
 							  message->notmuch,
 							  directory_id);
 
-	if (strlen (directory))
-	    filename = talloc_asprintf (message, "%s/%s/%s",
-					db_path, directory, basename);
+	parser.uri = &parsed;
+
+	if (strlen (directory)) {
+	    /* If directory is a URI, we don't need to append the db_path;
+	     * it is already an absolute path. */
+	    if (uriParseUriA (&parser, directory) != URI_SUCCESS ||
+		parsed.scheme.first == NULL)
+		filename = talloc_asprintf (message, "%s/%s/%s",
+					    db_path, directory, basename);
+	    else
+		filename = talloc_asprintf (message, "%s/%s",
+					    directory, basename);
+	    uriFreeUriMembersA (&parsed);
+	}
 	else
 	    filename = talloc_asprintf (message, "%s/%s",
 					db_path, basename);
-- 
1.7.9.5



More information about the notmuch mailing list