]> git.notmuchmail.org Git - notmuch/blob - test/make-db-version.cc
lib/message: catch exception in n_m_get_thread_id
[notmuch] / test / make-db-version.cc
1 /* Create an empty notmuch database with a specific version and
2  * features. */
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <sys/stat.h>
7 #include <sys/types.h>
8
9 #include <xapian.h>
10
11 int
12 main (int argc, char **argv)
13 {
14     if (argc != 4) {
15         fprintf (stderr, "Usage: %s mailpath version features\n", argv[0]);
16         exit (2);
17     }
18
19     std::string nmpath (argv[1]);
20     nmpath += "/.notmuch";
21     if (mkdir (nmpath.c_str (), 0777) < 0) {
22         perror (("failed to create " + nmpath).c_str ());
23         exit (1);
24     }
25
26     try {
27         Xapian::WritableDatabase db (
28             nmpath + "/xapian", Xapian::DB_CREATE_OR_OPEN);
29         db.set_metadata ("version", argv[2]);
30         db.set_metadata ("features", argv[3]);
31         db.commit ();
32     } catch (const Xapian::Error &e) {
33         fprintf (stderr, "%s\n", e.get_description ().c_str ());
34         exit (1);
35     }
36 }