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 DBA066DE137E
\r
6 for <notmuch@notmuchmail.org>; Sat, 23 Jan 2016 07:00:14 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.31 tagged_above=-999 required=5 tests=[AWL=0.241,
\r
12 RP_MATCHES_RCVD=-0.55, SPF_PASS=-0.001] autolearn=disabled
\r
13 Received: from arlo.cworth.org ([127.0.0.1])
\r
14 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id aALqoui491bC for <notmuch@notmuchmail.org>;
\r
16 Sat, 23 Jan 2016 07:00:13 -0800 (PST)
\r
17 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])
\r
18 by arlo.cworth.org (Postfix) with ESMTPS id 735976DE091B
\r
19 for <notmuch@notmuchmail.org>; Sat, 23 Jan 2016 07:00:12 -0800 (PST)
\r
20 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)
\r
21 (envelope-from <bremner@tethera.net>)
\r
22 id 1aMzf3-00016G-Au; Sat, 23 Jan 2016 09:59:33 -0500
\r
23 Received: (nullmailer pid 4051 invoked by uid 1000);
\r
24 Sat, 23 Jan 2016 15:00:07 -0000
\r
25 From: David Bremner <david@tethera.net>
\r
26 To: notmuch@notmuchmail.org
\r
27 Subject: [PATCH 5/5] CLI: optionally restore config data.
\r
28 Date: Sat, 23 Jan 2016 10:59:58 -0400
\r
29 Message-Id: <1453561198-2893-6-git-send-email-david@tethera.net>
\r
30 X-Mailer: git-send-email 2.6.4
\r
31 In-Reply-To: <1453561198-2893-1-git-send-email-david@tethera.net>
\r
32 References: <1453561198-2893-1-git-send-email-david@tethera.net>
\r
33 X-BeenThere: notmuch@notmuchmail.org
\r
34 X-Mailman-Version: 2.1.20
\r
36 List-Id: "Use and development of the notmuch mail system."
\r
37 <notmuch.notmuchmail.org>
\r
38 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
39 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
41 List-Post: <mailto:notmuch@notmuchmail.org>
\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
43 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
45 X-List-Received-Date: Sat, 23 Jan 2016 15:00:14 -0000
\r
47 Like the corresponding change to dump, this needs documentation
\r
49 notmuch-restore.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++
\r
50 test/T590-libconfig.sh | 11 +++++++++++
\r
51 2 files changed, 64 insertions(+)
\r
53 diff --git a/notmuch-restore.c b/notmuch-restore.c
\r
54 index 9abc64f..e06fbde 100644
\r
55 --- a/notmuch-restore.c
\r
56 +++ b/notmuch-restore.c
\r
58 #include "string-util.h"
\r
59 #include "zlib-extra.h"
\r
62 +process_config_line(notmuch_database_t *notmuch, const char* line){
\r
63 + const char *key_p, *val_p;
\r
65 + size_t key_len,val_len;
\r
66 + const char *delim=" \t\n";
\r
67 + int ret = EXIT_FAILURE;
\r
69 + void *local = talloc_new(NULL);
\r
71 + key_p = strtok_len_c(line, delim, &key_len);
\r
72 + val_p = strtok_len_c(key_p+key_len, delim, &val_len);
\r
74 + key = talloc_strndup(local, key_p, key_len);
\r
75 + val = talloc_strndup(local, val_p, val_len);
\r
76 + if (hex_decode_inplace (key) != HEX_SUCCESS ||
\r
77 + hex_decode_inplace (val) != HEX_SUCCESS ) {
\r
78 + fprintf (stderr, "hex decoding failure on line %s\n", line);
\r
82 + if (print_status_database ("notmuch restore", notmuch,
\r
83 + notmuch_database_set_config (notmuch, key, val)))
\r
86 + ret = EXIT_SUCCESS;
\r
89 + talloc_free (local);
\r
93 static regex_t regex;
\r
95 /* Non-zero return indicates an error in retrieving the message,
\r
96 @@ -137,6 +169,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
101 int input_format = DUMP_FORMAT_AUTO;
\r
103 if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
104 @@ -152,6 +185,10 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
105 { "batch-tag", DUMP_FORMAT_BATCH_TAG },
\r
106 { "sup", DUMP_FORMAT_SUP },
\r
108 + { NOTMUCH_OPT_KEYWORD_FLAGS, &include, "include", 'I',
\r
109 + (notmuch_keyword_t []){ { "config", DUMP_INCLUDE_CONFIG },
\r
110 + { "tags", DUMP_INCLUDE_TAGS} } },
\r
112 { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },
\r
113 { NOTMUCH_OPT_BOOLEAN, &accumulate, "accumulate", 'a', 0 },
\r
114 { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
\r
115 @@ -167,6 +204,10 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
116 notmuch_process_shared_options (argv[0]);
\r
117 notmuch_exit_if_unmatched_db_uuid (notmuch);
\r
119 + if (include == 0) {
\r
120 + include = DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS;
\r
123 name_for_error = input_file_name ? input_file_name : "stdin";
\r
126 @@ -225,11 +266,23 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
127 ret = EXIT_FAILURE;
\r
131 + if ((include & DUMP_INCLUDE_CONFIG) && line_len >= 2 && line[0] == '#' && line[1] == '@') {
\r
132 + ret = process_config_line(notmuch, line+2);
\r
137 } while ((line_len == 0) ||
\r
138 (line[0] == '#') ||
\r
139 /* the cast is safe because we checked about for line_len < 0 */
\r
140 (strspn (line, " \t\n") == (unsigned)line_len));
\r
142 + if (! (include & DUMP_INCLUDE_TAGS)) {
\r
143 + ret = EXIT_SUCCESS;
\r
148 for (p = line; (input_format == DUMP_FORMAT_AUTO) && *p; p++) {
\r
150 diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
\r
151 index 5ea5300..9c1e566 100755
\r
152 --- a/test/T590-libconfig.sh
\r
153 +++ b/test/T590-libconfig.sh
\r
154 @@ -132,4 +132,15 @@ cat <<'EOF' >EXPECTED
\r
156 test_expect_equal_file EXPECTED OUTPUT
\r
158 +test_begin_subtest "restore config"
\r
159 +notmuch dump --include=config >EXPECTED
\r
160 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
162 + RUN(notmuch_database_set_config (db, "testkey1", "mutatedvalue"));
\r
165 +notmuch restore --include=config <EXPECTED
\r
166 +notmuch dump --include=config >OUTPUT
\r
167 +test_expect_equal_file EXPECTED OUTPUT
\r