static int remove_filename(notmuch_database_t *db, const char *path) { notmuch_status_t st; notmuch_message_t *msg = NULL; dprint(2, (debugfile, "nm: removing filename '%s'\n", path)); st = notmuch_database_begin_atomic(db); if (st) return -1; st = notmuch_database_find_message_by_filename(db, path, &msg); if (st || !msg) return -1; st = notmuch_database_remove_message(db, path); if (st != NOTMUCH_STATUS_SUCCESS && st != NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) dprint(1, (debugfile, "nm: failed to remove '%s' [st=%d]\n", path, (int) st)); if (st == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) notmuch_message_maildir_flags_to_tags(msg); notmuch_message_destroy(msg); notmuch_database_end_atomic(db); return 0; }
static int remove_filename(struct nm_ctxdata *data, const char *path) { notmuch_status_t st; notmuch_filenames_t *ls; notmuch_message_t *msg = NULL; notmuch_database_t *db = get_db(data, TRUE); int trans; dprint(2, (debugfile, "nm: remove filename '%s'\n", path)); if (!db) return -1; st = notmuch_database_find_message_by_filename(db, path, &msg); if (st || !msg) return -1; trans = db_trans_begin(data); if (trans < 0) return -1; /* * note that unlink() is probably unnecessary here, it's already removed * by mh_sync_mailbox_message(), but for sure... */ st = notmuch_database_remove_message(db, path); switch (st) { case NOTMUCH_STATUS_SUCCESS: dprint(2, (debugfile, "nm: remove success, call unlink\n")); unlink(path); break; case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: dprint(2, (debugfile, "nm: remove succes (duplicate), call unlink\n")); unlink(path); for (ls = notmuch_message_get_filenames(msg); ls && notmuch_filenames_valid(ls); notmuch_filenames_move_to_next(ls)) { path = notmuch_filenames_get(ls); dprint(2, (debugfile, "nm: remove duplicate: '%s'\n", path)); unlink(path); notmuch_database_remove_message(db, path); } break; default: dprint(1, (debugfile, "nm: failed to remove '%s' [st=%d]\n", path, (int) st)); break; } notmuch_message_destroy(msg); if (trans) db_trans_end(data); return 0; }
/* * call-seq: DB.find_message_by_filename(path) => MESSAGE or nil * * Find a message by filename. */ VALUE notmuch_rb_database_find_message_by_filename (VALUE self, VALUE pathv) { const char *path; notmuch_status_t ret; notmuch_database_t *db; notmuch_message_t *message; Data_Get_Notmuch_Database (self, db); SafeStringValue (pathv); path = RSTRING_PTR (pathv); ret = notmuch_database_find_message_by_filename (db, path, &message); notmuch_rb_status_raise (ret); if (message) return Data_Wrap_Struct (notmuch_rb_cMessage, NULL, NULL, message); return Qnil; }