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 mS20FBpV8l+oDwAA0tVLHw (envelope-from ) for ; Sun, 03 Jan 2021 23:36:58 +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 iIM0EBpV8l9FPgAA1q6Kng (envelope-from ) for ; Sun, 03 Jan 2021 23:36:58 +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 C1CEB94038E for ; Sun, 3 Jan 2021 23:36:57 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 22FEB29D7C; Sun, 3 Jan 2021 18:36:23 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 7AC7629D49 for ; Sun, 3 Jan 2021 18:36:05 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id 726375FF47; Sun, 3 Jan 2021 18:36:05 -0500 (EST) Received: (nullmailer pid 126222 invoked by uid 1000); Sun, 03 Jan 2021 23:35:56 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 14/36] cli/dump: convert to new config framework Date: Sun, 3 Jan 2021 19:35:25 -0400 Message-Id: <20210103233547.122707-15-david@tethera.net> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210103233547.122707-1-david@tethera.net> References: <20210103233547.122707-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: CGYJ6C5DI6M33VIMFJA6OEFIUEBB47A7 X-Message-ID-Hash: CGYJ6C5DI6M33VIMFJA6OEFIUEBB47A7 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.88 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: C1CEB94038E X-Spam-Score: -0.88 X-Migadu-Scanner: scn0.migadu.com X-TUID: OK1/XvVc0/vT 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..131daa01 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 | sort >> 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 | sort >> OUTPUT +cat < EXPECTED +Before: +#notmuch-dump batch-tag:3 tags + +After: +#notmuch-dump batch-tag:3 tags ++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:20091117190054.GU3165@dottiness.seas.harvard.edu ++inbox +signed +unread -- id:20091117203301.GV3165@dottiness.seas.harvard.edu ++inbox +signed +unread -- id:20091118002059.067214ed@hikari ++inbox +signed +unread -- id:20091118005040.GA25380@dottiness.seas.harvard.edu ++inbox +signed +unread -- id:87iqd9rn3l.fsf@vertex.dottedmag +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