From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id mND+EOM15V/EGgAA0tVLHw (envelope-from ) for ; Fri, 25 Dec 2020 00:44:19 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id wETLDOM15V8IZgAA1q6Kng (envelope-from ) for ; Fri, 25 Dec 2020 00:44:19 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D3B819403A9 for ; Fri, 25 Dec 2020 00:44:18 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 8984A29D33; Thu, 24 Dec 2020 19:43:24 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 7FA4A29CDD for ; Thu, 24 Dec 2020 19:42:53 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id 656135FC36; Thu, 24 Dec 2020 19:42:53 -0500 (EST) Received: (nullmailer pid 650451 invoked by uid 1000); Fri, 25 Dec 2020 00:42:36 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 12/24] cli/dump: convert to new config framework Date: Thu, 24 Dec 2020 20:42:16 -0400 Message-Id: <20201225004228.647328-13-david@tethera.net> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201225004228.647328-1-david@tethera.net> References: <20201225004228.647328-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: O2TZS3XI3QS5DQQQQ6PSDO27HLX4KISQ X-Message-ID-Hash: O2TZS3XI3QS5DQQQQ6PSDO27HLX4KISQ X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 0.60 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: D3B819403A9 X-Spam-Score: 0.60 X-Migadu-Scanner: scn1.migadu.com X-TUID: n6abGcGRtc8w This conversion is trivial because the only configuration information accessed by dump is that stored in the database (in order to dump it). We do need to be careful to keep the write lock on the database to ensure dump consistency. --- notmuch-dump.c | 7 +------ notmuch.c | 2 +- test/T240-dump-restore.sh | 30 +++++++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/notmuch-dump.c b/notmuch-dump.c index eb629dc9..d7017929 100644 --- a/notmuch-dump.c +++ b/notmuch-dump.c @@ -361,16 +361,11 @@ notmuch_database_dump (notmuch_database_t *notmuch, } int -notmuch_dump_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) +notmuch_dump_command (unused(notmuch_config_t *config), notmuch_database_t *notmuch , int argc, char *argv[]) { - notmuch_database_t *notmuch; const char *query_str = NULL; int ret; - if (notmuch_database_open (notmuch_config_get_database_path (config), - NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much)) - return EXIT_FAILURE; - notmuch_exit_if_unmatched_db_uuid (notmuch); const char *output_file_name = NULL; diff --git a/notmuch.c b/notmuch.c index 40527893..b10cc702 100644 --- a/notmuch.c +++ b/notmuch.c @@ -159,7 +159,7 @@ static command_t commands[] = { "Construct a reply template for a set of messages." }, { "tag", notmuch_tag_command, NOTMUCH_COMMAND_CONFIG_OPEN, "Add/remove tags for all messages matching the search terms." }, - { "dump", notmuch_dump_command, NOTMUCH_COMMAND_CONFIG_OPEN, + { "dump", notmuch_dump_command, NOTMUCH_COMMAND_DATABASE_EARLY | NOTMUCH_COMMAND_DATABASE_WRITE, "Create a plain-text dump of the tags for each message." }, { "restore", notmuch_restore_command, NOTMUCH_COMMAND_CONFIG_OPEN, "Restore the tags from the given dump file (see 'dump')." }, diff --git a/test/T240-dump-restore.sh b/test/T240-dump-restore.sh index 0870ff92..b3782745 100755 --- a/test/T240-dump-restore.sh +++ b/test/T240-dump-restore.sh @@ -82,6 +82,33 @@ test_begin_subtest "dump --output=outfile --" notmuch dump --output=dump-1-arg-dash.actual -- test_expect_equal_file dump.expected dump-1-arg-dash.actual +# configuration + +test_begin_subtest "dump with saved query from config file" +query_name="test${RANDOM}" +printf "Before:\n" > OUTPUT +notmuch dump --include=tags query:$query_name >> OUTPUT +printf "\nAfter:\n" >> OUTPUT +cp notmuch-config old-config +printf "\n[query]\n${query_name} = tag:signed\n" >> notmuch-config +notmuch dump --include=tags query:$query_name >> OUTPUT +cat < EXPECTED +Before: +#notmuch-dump batch-tag:3 tags + +After: +#notmuch-dump batch-tag:3 tags ++inbox +signed +unread -- id:20091118002059.067214ed@hikari ++attachment +inbox +signed +unread -- id:20091118005829.GB25380@dottiness.seas.harvard.edu ++attachment +inbox +signed +unread -- id:20091118010116.GC25380@dottiness.seas.harvard.edu ++inbox +signed +unread -- id:20091118005040.GA25380@dottiness.seas.harvard.edu ++inbox +signed +unread -- id:87iqd9rn3l.fsf@vertex.dottedmag ++inbox +signed +unread -- id:20091117203301.GV3165@dottiness.seas.harvard.edu ++inbox +signed +unread -- id:20091117190054.GU3165@dottiness.seas.harvard.edu +EOF +cp old-config notmuch-config +test_expect_equal_file EXPECTED OUTPUT + # gzipped output test_begin_subtest "dump --gzip" @@ -322,6 +349,7 @@ EOF test_expect_equal_file EXPECTED OUTPUT +backup_database test_begin_subtest 'roundtripping random message-ids and tags' ${TEST_DIRECTORY}/random-corpus --config-path=${NOTMUCH_CONFIG} \ @@ -338,7 +366,7 @@ test_begin_subtest 'roundtripping random message-ids and tags' sort > OUTPUT.$test_count test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count +restore_database test_done -# Note the database is "poisoned" for sup format at this point. -- 2.29.2