From: Gaute Hope <eg@gaute.vetsj.com>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Subject: Re: add status value to _notmuch_message_ensure_metadata
Date: Mon, 20 Feb 2017 09:44:06 +0000 [thread overview]
Message-ID: <1487583702.5ghl7kdkaw.astroid@strange.none> (raw)
In-Reply-To: <1487582192.57s86yczcg.astroid@strange.none>
[-- Attachment #1.1: Type: text/plain, Size: 530 bytes --]
Gaute Hope writes on februar 20, 2017 10:27:
> David Bremner writes on februar 18, 2017 15:45:
>> In id:1487339566.mz8acpov1j.astroid@strange.none , Gaute provided a
>> traceback of an uncaught Xapian::DatabaseModifiedError. The fix for
>> this is simple, but somewhat intrusive.
>>
>> [...]
>>
>> I haven't tested against Gaute's test case (needs more boost than I
>> have handy).
Alright then, attached is a non-boost version that takes a notmuch db
path (absolute) as the first argument (no warranty).
- gaute
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: test_notmuch_standalone.cc --]
[-- Type: text/x-c++src; name=test_notmuch_standalone.cc, Size: 5469 bytes --]
# include <iostream>
# include <unistd.h>
# include <notmuch.h>
using std::cout;
using std::endl;
int main (int argc, char **argv) {
if (argc < 2) {
std::cerr << "error: specify the path to the test notmuch database" << endl;
return 1;
}
std::string path_db;
path_db = argv[1];
cout << "using db: " << path_db << endl;
notmuch_database_t * nm_db;
notmuch_status_t s =
notmuch_database_open (
path_db.c_str(),
notmuch_database_mode_t::NOTMUCH_DATABASE_MODE_READ_ONLY,
&nm_db);
cout << "db: running test query.." << endl;
notmuch_query_t * q = notmuch_query_create (nm_db, "*");
unsigned int c;
notmuch_status_t st = notmuch_query_count_threads_st (q, &c); // destructive
notmuch_query_destroy (q);
q = notmuch_query_create (nm_db, "*");
cout << "query: " << notmuch_query_get_query_string (q) << ", approx: "
<< c << " threads." << endl;
notmuch_threads_t * threads;
notmuch_thread_t * thread;
st = notmuch_query_search_threads_st (q, &threads);
std::string thread_id;
int i = 0;
for (; notmuch_threads_valid (threads);
notmuch_threads_move_to_next (threads)) {
thread = notmuch_threads_get (threads);
i++;
if (i == 3)
thread_id = notmuch_thread_get_thread_id (thread);
notmuch_thread_destroy (thread);
if (i == 3) break;
}
cout << "thread id to change: " << thread_id << ", thread no: " << i << endl;
notmuch_query_destroy (q);
/* restart query */
cout << "restarting query.." << endl;
q = notmuch_query_create (nm_db, "*");
st = notmuch_query_search_threads_st (q, &threads);
i = 0;
int stop = 2;
cout << "moving to thread: " << stop << endl;
for ( ; notmuch_threads_valid (threads);
notmuch_threads_move_to_next (threads))
{
thread = notmuch_threads_get (threads);
notmuch_thread_get_thread_id (thread);
i++;
cout << "tags: ";
/* get tags */
notmuch_tags_t *tags;
const char *tag;
for (tags = notmuch_thread_get_tags (thread);
notmuch_tags_valid (tags);
notmuch_tags_move_to_next (tags))
{
tag = notmuch_tags_get (tags);
cout << tag << " ";
}
cout << endl;
notmuch_thread_destroy (thread);
if (i == stop) break;
}
/* now open a new db instance, modify the already loaded thread and
* continue loading the original query */
notmuch_database_t * nm_db2;
s = notmuch_database_open (
path_db.c_str(),
notmuch_database_mode_t::NOTMUCH_DATABASE_MODE_READ_WRITE,
&nm_db2);
char qry_s[256];
sprintf (qry_s, "thread:%s", thread_id.c_str ());
notmuch_query_t * q2 = notmuch_query_create (nm_db2, qry_s);
notmuch_threads_t * ts2;
notmuch_thread_t * t2;
st = notmuch_query_search_threads_st (q2, &ts2);
for ( ; notmuch_threads_valid (ts2);
notmuch_threads_move_to_next (ts2))
{
t2 = notmuch_threads_get (ts2);
std::string thread_id = notmuch_thread_get_thread_id (t2);
/* remove unread tag */
notmuch_messages_t * ms = notmuch_thread_get_messages (t2);
notmuch_message_t * m;
for (; notmuch_messages_valid (ms); notmuch_messages_move_to_next (ms)) {
m = notmuch_messages_get (ms);
st = notmuch_message_remove_tag (m, "unread");
notmuch_message_destroy (m);
}
notmuch_messages_destroy (ms);
notmuch_thread_destroy (t2);
break;
}
notmuch_query_destroy (q2);
notmuch_database_close (nm_db2);
/* re-add unread tag */
s = notmuch_database_open (
path_db.c_str(),
notmuch_database_mode_t::NOTMUCH_DATABASE_MODE_READ_WRITE,
&nm_db2);
q2 = notmuch_query_create (nm_db2, qry_s);
st = notmuch_query_search_threads_st (q2, &ts2);
for ( ; notmuch_threads_valid (ts2);
notmuch_threads_move_to_next (ts2))
{
t2 = notmuch_threads_get (ts2);
std::string thread_id = notmuch_thread_get_thread_id (t2);
/* remove unread tag */
notmuch_messages_t * ms = notmuch_thread_get_messages (t2);
notmuch_message_t * m;
for (; notmuch_messages_valid (ms); notmuch_messages_move_to_next (ms)) {
m = notmuch_messages_get (ms);
st = notmuch_message_add_tag (m, "unread");
notmuch_message_destroy (m);
}
notmuch_messages_destroy (ms);
notmuch_thread_destroy (t2);
break;
}
notmuch_query_destroy (q2);
notmuch_database_close (nm_db2);
/* continue loading */
cout << "continue loading.." << endl;
for ( ; notmuch_threads_valid (threads);
notmuch_threads_move_to_next (threads))
{
if (threads == NULL) {
cout << "threads == NULL" << endl;
} else {
cout << "threads != NULL" << endl;
}
thread = notmuch_threads_get (threads);
if (thread == NULL) {
cout << "thread == NULL" << endl;
} else {
cout << "thread != NULL" << endl;
}
cout << "loading: " << i;
const char * cid = notmuch_thread_get_thread_id (thread);
std::string tid = "";
if (cid != NULL) tid = cid;
cout << ": " << tid << endl;
/* get tags */
notmuch_tags_t *tags;
const char *tag;
cout << "tags: ";
for (tags = notmuch_thread_get_tags (thread);
notmuch_tags_valid (tags);
notmuch_tags_move_to_next (tags))
{
tag = notmuch_tags_get (tags);
cout << tag << " ";
}
cout << endl;
i++;
notmuch_thread_destroy (thread);
}
notmuch_database_close (nm_db);
return 0;
}
[-- Attachment #2: Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2017-02-20 9:44 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-18 14:45 add status value to _notmuch_message_ensure_metadata David Bremner
2017-02-18 14:45 ` [PATCH 1/8] lib: make _notmuch_message_ensure_metadata static David Bremner
2017-02-23 12:59 ` David Bremner
2017-02-18 14:45 ` [PATCH 2/8] lib: add status return to _notmuch_message_ensure_metadata David Bremner
2017-02-18 14:45 ` [PATCH 3/8] lib: propagate error return from some calls to _n_m_e_metadata David Bremner
2017-02-18 14:45 ` [PATCH 4/8] lib: push error from nme_metadata through nme_filename_list David Bremner
2017-02-18 14:45 ` [PATCH 5/8] lib: make _notmuch_message_ensure_property_map static David Bremner
2017-02-18 14:45 ` [PATCH 6/8] lib: propagate errors from nme_metadata through properties API David Bremner
2017-02-18 14:45 ` [PATCH 7/8] lib: add notmuch_message_get_database to public API David Bremner
2017-02-18 14:45 ` [PATCH 8/8] lib: add status return to notmuch_message_get_flag David Bremner
2017-02-20 9:27 ` add status value to _notmuch_message_ensure_metadata Gaute Hope
2017-02-20 9:44 ` Gaute Hope [this message]
2017-02-23 0:58 ` David Bremner
2017-02-23 7:46 ` Gaute Hope
2017-02-23 11:59 ` David Bremner
2017-02-24 2:00 ` [RFC patch 1/2] lib: add notmuch_database_reopen David Bremner
2017-02-24 2:00 ` [RFC patch 2/2] lib: handle DatabaseModifiedError in _n_message_ensure_metadata David Bremner
2017-02-24 2:49 ` David Bremner
2017-02-24 10:21 ` Gaute Hope
2017-02-24 11:40 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1487583702.5ghl7kdkaw.astroid@strange.none \
--to=eg@gaute.vetsj.com \
--cc=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).