return strdup (key);
}
+/* Given a legal 'path' for the database, return the relative path.
+ *
+ * The return value will be a pointer to the originl path contents,
+ * and will be either the original string (if 'path' was relative) or
+ * a portion of the string (if path was absolute and begins with the
+ * database path).
+ */
+const char *
+_notmuch_database_relative_path (notmuch_database_t *notmuch,
+ const char *path)
+{
+ const char *db_path, *relative;
+ unsigned int db_path_len;
+
+ db_path = notmuch_database_get_path (notmuch);
+ db_path_len = strlen (db_path);
+
+ relative = path;
+
+ if (*relative == '/') {
+ while (*relative == '/' && *(relative+1) == '/')
+ relative++;
+
+ if (strncmp (relative, db_path, db_path_len) == 0)
+ {
+ relative += db_path_len;
+ while (*relative == '/')
+ relative++;
+ }
+ }
+
+ return relative;
+}
+
notmuch_status_t
notmuch_database_set_timestamp (notmuch_database_t *notmuch,
const char *key, time_t timestamp)
_notmuch_message_set_filename (notmuch_message_t *message,
const char *filename)
{
- const char *s;
- const char *db_path;
- unsigned int db_path_len;
+ const char *relative;
if (message->filename) {
talloc_free (message->filename);
if (filename == NULL)
INTERNAL_ERROR ("Message filename cannot be NULL.");
- s = filename;
-
- db_path = notmuch_database_get_path (message->notmuch);
- db_path_len = strlen (db_path);
-
- if (*s == '/' && strlen (s) > db_path_len
- && strncmp (s, db_path, db_path_len) == 0)
- {
- s += db_path_len;
- while (*s == '/') s++;
-
- if (!*s)
- INTERNAL_ERROR ("Message filename was same as db prefix.");
- }
-
- message->doc.set_data (s);
+ relative = _notmuch_database_relative_path (message->notmuch, filename);
+ message->doc.set_data (relative);
}
const char *