From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id qOh/MPtHHWAPOwAA0tVLHw (envelope-from ) for ; Fri, 05 Feb 2021 13:28:27 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id QM1SLPtHHWDPbAAAbx9fmQ (envelope-from ) for ; Fri, 05 Feb 2021 13:28:27 +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 3CC529402BD for ; Fri, 5 Feb 2021 13:28:27 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 2EED11FC0F; Fri, 5 Feb 2021 08:27:33 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id C6A011FBBC for ; Fri, 5 Feb 2021 08:27:13 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id BE9A86067F; Fri, 5 Feb 2021 08:27:13 -0500 (EST) Received: (nullmailer pid 3258404 invoked by uid 1000); Fri, 05 Feb 2021 13:27:02 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 15/39] CLI/restore: convert to new config framework Date: Fri, 5 Feb 2021 09:26:30 -0400 Message-Id: <20210205132654.3258292-16-david@tethera.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210205132654.3258292-1-david@tethera.net> References: <20210205132654.3258292-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: BKKZE7REU5CDPVROIHWSPDOO7V5BS52S X-Message-ID-Hash: BKKZE7REU5CDPVROIHWSPDOO7V5BS52S 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.83 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: 3CC529402BD X-Spam-Score: -0.83 X-Migadu-Scanner: scn1.migadu.com X-TUID: yE/4ufwV3Kz3 Switch one configuration check to new n_c_get_bool function, and switch use of config as talloc context to notmuch. --- notmuch-restore.c | 17 ++++++++++------- notmuch.c | 2 +- test/T035-read-config.sh | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/notmuch-restore.c b/notmuch-restore.c index 544f4228..ce07f89d 100644 --- a/notmuch-restore.c +++ b/notmuch-restore.c @@ -219,9 +219,8 @@ parse_sup_line (void *ctx, char *line, } int -notmuch_restore_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) +notmuch_restore_command (unused(notmuch_config_t *config), notmuch_database_t *notmuch, int argc, char *argv[]) { - notmuch_database_t *notmuch; bool accumulate = false; tag_op_flag_t flags = 0; tag_op_list_t *tag_ops; @@ -238,12 +237,16 @@ notmuch_restore_command (notmuch_config_t *config, unused(notmuch_database_t *no int include = 0; int input_format = DUMP_FORMAT_AUTO; int errnum; + notmuch_bool_t synchronize_flags; - if (notmuch_database_open (notmuch_config_get_database_path (config), - NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much)) + if (print_status_database ( + "notmuch restore", + notmuch, + notmuch_config_get_bool (notmuch, NOTMUCH_CONFIG_SYNC_MAILDIR_FLAGS, + &synchronize_flags))) return EXIT_FAILURE; - if (notmuch_config_get_maildir_synchronize_flags (config)) + if (synchronize_flags) flags |= TAG_FLAG_MAILDIR_SYNC; notmuch_opt_desc_t options[] = { @@ -310,7 +313,7 @@ notmuch_restore_command (notmuch_config_t *config, unused(notmuch_database_t *no goto DONE; } - tag_ops = tag_op_list_create (config); + tag_ops = tag_op_list_create (notmuch); if (tag_ops == NULL) { fprintf (stderr, "Out of memory.\n"); ret = EXIT_FAILURE; @@ -377,7 +380,7 @@ notmuch_restore_command (notmuch_config_t *config, unused(notmuch_database_t *no if (line_ctx != NULL) talloc_free (line_ctx); - line_ctx = talloc_new (config); + line_ctx = talloc_new (notmuch); if ((include & DUMP_INCLUDE_PROPERTIES) && line_len >= 2 && line[0] == '#' && line[1] == '=') { ret = process_properties_line (notmuch, line + 2); diff --git a/notmuch.c b/notmuch.c index b10cc702..4258ed43 100644 --- a/notmuch.c +++ b/notmuch.c @@ -161,7 +161,7 @@ static command_t commands[] = { "Add/remove tags for all messages matching the search terms." }, { "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", notmuch_restore_command, NOTMUCH_COMMAND_DATABASE_EARLY | NOTMUCH_COMMAND_DATABASE_WRITE, "Restore the tags from the given dump file (see 'dump')." }, { "compact", notmuch_compact_command, NOTMUCH_COMMAND_CONFIG_OPEN, "Compact the notmuch database." }, diff --git a/test/T035-read-config.sh b/test/T035-read-config.sh index 9e506dfa..35fbd600 100755 --- a/test/T035-read-config.sh +++ b/test/T035-read-config.sh @@ -122,4 +122,24 @@ notmuch dump --include=tags query:$query_name | sort >> OUTPUT restore_config test_expect_equal_file EXPECTED OUTPUT +test_begin_subtest "restore with xdg config" +backup_config +notmuch dump '*' > EXPECTED +notmuch tag -inbox '*' +xdg_config +notmuch restore --input=EXPECTED +notmuch dump > OUTPUT +restore_config +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "restore with xdg+profile config" +backup_config +notmuch dump '*' > EXPECTED +notmuch tag -inbox '*' +xdg_config work +notmuch restore --input=EXPECTED +notmuch dump > OUTPUT +restore_config +test_expect_equal_file EXPECTED OUTPUT + test_done -- 2.30.0