X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=lib%2Fdatabase.cc;h=e27a0e1664cfac7d2731402f7e3c675c19f57eda;hb=3f3c446c40e6e7661620645f1c152968b5590f10;hp=716982d0e4cd279e9b734941c78e56aca84fbf37;hpb=0c950146a14fa2bb0a0bf542073b2cdca141afd1;p=notmuch diff --git a/lib/database.cc b/lib/database.cc index 716982d0..e27a0e16 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -1248,13 +1248,16 @@ _notmuch_database_get_directory_path (void *ctx, * database path), return a new string (with 'ctx' as the talloc * owner) suitable for use as a direntry term value. * - * The necessary directory documents will be created in the database - * as needed. + * If (flags & NOTMUCH_FIND_CREATE), the necessary directory documents + * will be created in the database as needed. Otherwise, if the + * necessary directory documents do not exist, this sets + * *direntry to NULL and returns NOTMUCH_STATUS_SUCCESS. */ notmuch_status_t _notmuch_database_filename_to_direntry (void *ctx, notmuch_database_t *notmuch, const char *filename, + notmuch_find_flags_t flags, char **direntry) { const char *relative, *directory, *basename; @@ -1268,10 +1271,12 @@ _notmuch_database_filename_to_direntry (void *ctx, if (status) return status; - status = _notmuch_database_find_directory_id (notmuch, directory, NOTMUCH_FIND_CREATE, + status = _notmuch_database_find_directory_id (notmuch, directory, flags, &directory_id); - if (status) + if (status || directory_id == (unsigned int)-1) { + *direntry = NULL; return status; + } *direntry = talloc_asprintf (ctx, "%u:%s", directory_id, basename); @@ -1323,12 +1328,9 @@ notmuch_database_get_directory (notmuch_database_t *notmuch, return NOTMUCH_STATUS_NULL_POINTER; *directory = NULL; - /* XXX Handle read-only databases properly */ - if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) - return NOTMUCH_STATUS_READ_ONLY_DATABASE; - try { - *directory = _notmuch_directory_create (notmuch, path, NOTMUCH_FIND_CREATE, &status); + *directory = _notmuch_directory_create (notmuch, path, + NOTMUCH_FIND_LOOKUP, &status); } catch (const Xapian::Error &error) { fprintf (stderr, "A Xapian exception occurred getting directory: %s.\n", error.get_msg().c_str()); @@ -1892,8 +1894,8 @@ notmuch_database_find_message_by_filename (notmuch_database_t *notmuch, local = talloc_new (notmuch); try { - status = _notmuch_database_filename_to_direntry (local, notmuch, - filename, &direntry); + status = _notmuch_database_filename_to_direntry ( + local, notmuch, filename, NOTMUCH_FIND_CREATE, &direntry); if (status) goto DONE;