Esempio n. 1
0
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;
}
Esempio n. 2
0
/*
 * call-seq: DB.begin_atomic => nil
 *
 * Begin an atomic database operation.
 */
VALUE
notmuch_rb_database_begin_atomic (VALUE self)
{
    notmuch_status_t ret;
    notmuch_database_t *db;

    Data_Get_Notmuch_Database (self, db);

    ret = notmuch_database_begin_atomic (db);
    notmuch_rb_status_raise (ret);

    return Qtrue;
}
Esempio n. 3
0
/* returns:	< 0 = error
 *		  1 = new transaction started
 *		  0 = already within transaction
 */
static int db_trans_begin(struct nm_ctxdata *data)
{
    if (!data || !data->db)
        return -1;

    if (!data->trans) {
        dprint(2, (debugfile, "nm: db trans start\n"));
        if (notmuch_database_begin_atomic(data->db))
            return -1;
        data->trans = 1;
        return 1;
    }

    return 0;
}
Esempio n. 4
0
static int add_filename(notmuch_database_t *db, const char *path, HEADER *h)
{
	int rc = -1;
	notmuch_status_t st;
	notmuch_message_t *msg;

	dprint(2, (debugfile, "nm: adding filename '%s'\n", path));

	st = notmuch_database_begin_atomic(db);
	if (st)
		return -1;

	st = notmuch_database_add_message(db, path, &msg);
	switch (st) {
	case NOTMUCH_STATUS_SUCCESS:
		if (h)
			update_tags(msg, nm_header_get_tags(h));
		break;
	case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
		notmuch_message_maildir_flags_to_tags(msg);
		break;
	default:
		dprint(1, (debugfile, "nm: failed to add '%s' [st=%d]\n",
					path, (int) st));
		goto done;
	}

	st = notmuch_database_end_atomic(db);
	if (st)
	    goto done;

	rc = 0;
done:
	if (msg)
	    notmuch_message_destroy(msg);
	return rc;
}