summaryrefslogtreecommitdiff
path: root/lib/database.cc
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2009-12-19 12:32:11 -0800
committerCarl Worth <cworth@cworth.org>2010-01-06 10:32:05 -0800
commitba12bf1f2625a34f960502a06ba8907445ef5257 (patch)
treec9a1bcafcf182044280916b01b0d7b67f3b931b0 /lib/database.cc
parent3a9c3ec9e719f0e5adefe0ceafffeb34c7a3917e (diff)
lib: Abstract the extraction of a relative path from set_filename
We'll soon be having multiple entry points that accept a filename path, so we want common code for getting a relative path from a potentially absolute path.
Diffstat (limited to 'lib/database.cc')
-rw-r--r--lib/database.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/database.cc b/lib/database.cc
index b6c4d07..261be01 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -587,6 +587,40 @@ timestamp_db_key (const char *key)
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)