1 Return-Path: <bremner@tethera.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by arlo.cworth.org (Postfix) with ESMTP id EC1116DE091C
\r
6 for <notmuch@notmuchmail.org>; Tue, 22 Mar 2016 03:56:01 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.029 tagged_above=-999 required=5
\r
12 tests=[AWL=-0.018, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]
\r
14 Received: from arlo.cworth.org ([127.0.0.1])
\r
15 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id 9ku7qh5qvpki for <notmuch@notmuchmail.org>;
\r
17 Tue, 22 Mar 2016 03:55:54 -0700 (PDT)
\r
18 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])
\r
19 by arlo.cworth.org (Postfix) with ESMTPS id B4CF76DE0217
\r
20 for <notmuch@notmuchmail.org>; Tue, 22 Mar 2016 03:55:24 -0700 (PDT)
\r
21 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)
\r
22 (envelope-from <bremner@tethera.net>)
\r
23 id 1aiJyi-00015Z-62; Tue, 22 Mar 2016 06:56:00 -0400
\r
24 Received: (nullmailer pid 14087 invoked by uid 1000);
\r
25 Tue, 22 Mar 2016 10:55:11 -0000
\r
26 From: David Bremner <david@tethera.net>
\r
27 To: notmuch@notmuchmail.org
\r
28 Subject: [PATCH 10/13] CLI: optionally restore config data.
\r
29 Date: Tue, 22 Mar 2016 07:54:51 -0300
\r
30 Message-Id: <1458644094-13951-11-git-send-email-david@tethera.net>
\r
31 X-Mailer: git-send-email 2.7.0
\r
32 In-Reply-To: <1458644094-13951-1-git-send-email-david@tethera.net>
\r
33 References: <1458644094-13951-1-git-send-email-david@tethera.net>
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.20
\r
37 List-Id: "Use and development of the notmuch mail system."
\r
38 <notmuch.notmuchmail.org>
\r
39 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
40 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
42 List-Post: <mailto:notmuch@notmuchmail.org>
\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
44 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
46 X-List-Received-Date: Tue, 22 Mar 2016 10:56:02 -0000
\r
48 Like the corresponding change to dump, this needs documentation
\r
50 notmuch-restore.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++
\r
51 test/T590-libconfig.sh | 11 +++++++++++
\r
52 2 files changed, 64 insertions(+)
\r
54 diff --git a/notmuch-restore.c b/notmuch-restore.c
\r
55 index 9abc64f..e06fbde 100644
\r
56 --- a/notmuch-restore.c
\r
57 +++ b/notmuch-restore.c
\r
59 #include "string-util.h"
\r
60 #include "zlib-extra.h"
\r
63 +process_config_line(notmuch_database_t *notmuch, const char* line){
\r
64 + const char *key_p, *val_p;
\r
66 + size_t key_len,val_len;
\r
67 + const char *delim=" \t\n";
\r
68 + int ret = EXIT_FAILURE;
\r
70 + void *local = talloc_new(NULL);
\r
72 + key_p = strtok_len_c(line, delim, &key_len);
\r
73 + val_p = strtok_len_c(key_p+key_len, delim, &val_len);
\r
75 + key = talloc_strndup(local, key_p, key_len);
\r
76 + val = talloc_strndup(local, val_p, val_len);
\r
77 + if (hex_decode_inplace (key) != HEX_SUCCESS ||
\r
78 + hex_decode_inplace (val) != HEX_SUCCESS ) {
\r
79 + fprintf (stderr, "hex decoding failure on line %s\n", line);
\r
83 + if (print_status_database ("notmuch restore", notmuch,
\r
84 + notmuch_database_set_config (notmuch, key, val)))
\r
87 + ret = EXIT_SUCCESS;
\r
90 + talloc_free (local);
\r
94 static regex_t regex;
\r
96 /* Non-zero return indicates an error in retrieving the message,
\r
97 @@ -137,6 +169,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
102 int input_format = DUMP_FORMAT_AUTO;
\r
104 if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
105 @@ -152,6 +185,10 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
106 { "batch-tag", DUMP_FORMAT_BATCH_TAG },
\r
107 { "sup", DUMP_FORMAT_SUP },
\r
109 + { NOTMUCH_OPT_KEYWORD_FLAGS, &include, "include", 'I',
\r
110 + (notmuch_keyword_t []){ { "config", DUMP_INCLUDE_CONFIG },
\r
111 + { "tags", DUMP_INCLUDE_TAGS} } },
\r
113 { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },
\r
114 { NOTMUCH_OPT_BOOLEAN, &accumulate, "accumulate", 'a', 0 },
\r
115 { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
\r
116 @@ -167,6 +204,10 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
117 notmuch_process_shared_options (argv[0]);
\r
118 notmuch_exit_if_unmatched_db_uuid (notmuch);
\r
120 + if (include == 0) {
\r
121 + include = DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS;
\r
124 name_for_error = input_file_name ? input_file_name : "stdin";
\r
127 @@ -225,11 +266,23 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
128 ret = EXIT_FAILURE;
\r
132 + if ((include & DUMP_INCLUDE_CONFIG) && line_len >= 2 && line[0] == '#' && line[1] == '@') {
\r
133 + ret = process_config_line(notmuch, line+2);
\r
138 } while ((line_len == 0) ||
\r
139 (line[0] == '#') ||
\r
140 /* the cast is safe because we checked about for line_len < 0 */
\r
141 (strspn (line, " \t\n") == (unsigned)line_len));
\r
143 + if (! (include & DUMP_INCLUDE_TAGS)) {
\r
144 + ret = EXIT_SUCCESS;
\r
149 for (p = line; (input_format == DUMP_FORMAT_AUTO) && *p; p++) {
\r
151 diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
\r
152 index 5ea5300..9c1e566 100755
\r
153 --- a/test/T590-libconfig.sh
\r
154 +++ b/test/T590-libconfig.sh
\r
155 @@ -132,4 +132,15 @@ cat <<'EOF' >EXPECTED
\r
157 test_expect_equal_file EXPECTED OUTPUT
\r
159 +test_begin_subtest "restore config"
\r
160 +notmuch dump --include=config >EXPECTED
\r
161 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
163 + RUN(notmuch_database_set_config (db, "testkey1", "mutatedvalue"));
\r
166 +notmuch restore --include=config <EXPECTED
\r
167 +notmuch dump --include=config >OUTPUT
\r
168 +test_expect_equal_file EXPECTED OUTPUT
\r