unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Kevin Boulain <kevin@boula.in>
To: notmuch@notmuchmail.org
Cc: Kevin Boulain <kevin@boula.in>
Subject: [PATCH 2/2] lib/message-property: sync removed properties to the database
Date: Wed,  1 Mar 2023 21:51:49 +0100	[thread overview]
Message-ID: <20230301205149.297637-2-kevin@boula.in> (raw)
In-Reply-To: <20230301205149.297637-1-kevin@boula.in>

_notmuch_message_remove_all_properties wasn't syncing the message back
to the database but was still invalidating the metadata, giving the
impression the properties had actually been removed.

Also move the metadata invalidation to _notmuch_message_remove_terms
to be closer to what's done in _notmuch_message_modify_property and
_notmuch_message_remove_term.
---
Don't we need to talloc_free the talloc_asprintf'd term_prefix?

 lib/message-property.cc       |  4 ++-
 lib/message.cc                |  2 ++
 test/T610-message-property.sh | 61 ++++++++++++++++-------------------
 3 files changed, 33 insertions(+), 34 deletions(-)

diff --git a/lib/message-property.cc b/lib/message-property.cc
index d5afa30c..0d658038 100644
--- a/lib/message-property.cc
+++ b/lib/message-property.cc
@@ -123,7 +123,6 @@ _notmuch_message_remove_all_properties (notmuch_message_t *message, const char *
     if (status)
 	return status;
 
-    _notmuch_message_invalidate_metadata (message, "property");
     if (key)
 	term_prefix = talloc_asprintf (message, "%s%s%s", _find_prefix ("property"), key,
 				       prefix ? "" : "=");
@@ -133,6 +132,9 @@ _notmuch_message_remove_all_properties (notmuch_message_t *message, const char *
     /* XXX better error reporting ? */
     _notmuch_message_remove_terms (message, term_prefix);
 
+    if (! _notmuch_message_frozen (message))
+	_notmuch_message_sync (message);
+
     return NOTMUCH_STATUS_SUCCESS;
 }
 
diff --git a/lib/message.cc b/lib/message.cc
index 1b1a071a..53f35dd1 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -719,6 +719,8 @@ _notmuch_message_remove_terms (notmuch_message_t *message, const char *prefix)
 	    /* Ignore failure to remove non-existent term. */
 	}
     }
+
+    _notmuch_message_invalidate_metadata (message, "property");
 }
 
 
diff --git a/test/T610-message-property.sh b/test/T610-message-property.sh
index 7ebddae3..dd397e16 100755
--- a/test/T610-message-property.sh
+++ b/test/T610-message-property.sh
@@ -89,17 +89,6 @@ testkey2 = NULL
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
-test_begin_subtest "notmuch_message_remove_all_properties"
-cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
-EXPECT0(notmuch_message_remove_all_properties (message, NULL));
-print_properties (message, "", FALSE);
-EOF
-cat <<'EOF' >EXPECTED
-== stdout ==
-== stderr ==
-EOF
-test_expect_equal_file EXPECTED OUTPUT
-
 test_begin_subtest "testing string map binary search (via message properties)"
 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
 {
@@ -162,6 +151,17 @@ testkey1 = testvalue1
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "notmuch_message_remove_all_properties"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+EXPECT0(notmuch_message_remove_all_properties (message, NULL));
+print_properties (message, "", FALSE);
+EOF
+cat <<'EOF' >EXPECTED
+== stdout ==
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 test_begin_subtest "notmuch_message_properties: multiple values"
 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
 EXPECT0(notmuch_message_add_property (message, "testkey1", "bob"));
@@ -173,7 +173,6 @@ cat <<'EOF' >EXPECTED
 == stdout ==
 testkey1 = alice
 testkey1 = bob
-testkey1 = testvalue1
 testkey1 = testvalue2
 == stderr ==
 EOF
@@ -186,23 +185,10 @@ EXPECT0(notmuch_message_add_property (message, "testkey3", "testvalue3"));
 EXPECT0(notmuch_message_add_property (message, "testkey3", "alice3"));
 print_properties (message, "testkey", FALSE);
 EOF
-# expected: 4 values for testkey1, 3 values for testkey3
-# they are not guaranteed to be sorted, so sort them, leaving the first
-# line '== stdout ==' and the end ('== stderr ==' and whatever error
-# may have been printed) alone
-mv OUTPUT unsorted_OUTPUT
-awk ' NR == 1 { print; next } \
-      NR < 6  { print | "sort"; next } \
-      NR == 6 { close("sort") } \
-      NR < 9  { print | "sort"; next } \
-      NR == 9 { close("sort") } \
-      { print }' unsorted_OUTPUT > OUTPUT
-rm unsorted_OUTPUT
 cat <<'EOF' >EXPECTED
 == stdout ==
 testkey1 = alice
 testkey1 = bob
-testkey1 = testvalue1
 testkey1 = testvalue2
 testkey3 = alice3
 testkey3 = bob3
@@ -246,9 +232,23 @@ cat <<'EOF' >EXPECTED
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "notmuch_message_remove_all_properties_with_prefix"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+EXPECT0(notmuch_message_remove_all_properties_with_prefix (message, "testkey3"));
+print_properties (message, "", FALSE);
+EOF
+cat <<'EOF' >EXPECTED
+== stdout ==
+testkey1 = alice
+testkey1 = bob
+testkey1 = testvalue2
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 test_begin_subtest "dump message properties"
 cat <<EOF > PROPERTIES
-#= 4EFC743A.3060609@april.org fancy%20key%20with%20%c3%a1cc%c3%a8nts=import%20value%20with%20= testkey1=alice testkey1=bob testkey1=testvalue1 testkey1=testvalue2 testkey3=alice3 testkey3=bob3 testkey3=testvalue3
+#= 4EFC743A.3060609@april.org fancy%20key%20with%20%c3%a1cc%c3%a8nts=import%20value%20with%20= testkey1=alice testkey1=bob testkey1=testvalue2
 EOF
 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
 EXPECT0(notmuch_message_add_property (message, "fancy key with áccènts", "import value with ="));
@@ -259,7 +259,7 @@ test_expect_equal_file PROPERTIES OUTPUT
 test_begin_subtest "dump _only_ message properties"
 cat <<EOF > EXPECTED
 #notmuch-dump batch-tag:3 properties
-#= 4EFC743A.3060609@april.org fancy%20key%20with%20%c3%a1cc%c3%a8nts=import%20value%20with%20= testkey1=alice testkey1=bob testkey1=testvalue1 testkey1=testvalue2 testkey3=alice3 testkey3=bob3 testkey3=testvalue3
+#= 4EFC743A.3060609@april.org fancy%20key%20with%20%c3%a1cc%c3%a8nts=import%20value%20with%20= testkey1=alice testkey1=bob testkey1=testvalue2
 EOF
 notmuch dump --include=properties > OUTPUT
 test_expect_equal_file EXPECTED OUTPUT
@@ -313,7 +313,7 @@ print("testkey3 = {0}".format(msg.get_property("testkey3")))
 EOF
 cat <<'EOF' > EXPECTED
 testkey1 = alice
-testkey3 = alice3
+testkey3 = None
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
@@ -328,7 +328,6 @@ EOF
 cat <<'EOF' > EXPECTED
 testkey1 = alice
 testkey1 = bob
-testkey1 = testvalue1
 testkey1 = testvalue2
 EOF
 test_expect_equal_file EXPECTED OUTPUT
@@ -344,11 +343,7 @@ EOF
 cat <<'EOF' > EXPECTED
 testkey1 = alice
 testkey1 = bob
-testkey1 = testvalue1
 testkey1 = testvalue2
-testkey3 = alice3
-testkey3 = bob3
-testkey3 = testvalue3
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 \r

  reply	other threads:[~2023-03-01 20:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-01 20:51 [PATCH 1/2] test: display key name in property tests Kevin Boulain
2023-03-01 20:51 ` Kevin Boulain [this message]
2023-03-02 22:39   ` [PATCH 2/2] lib/message-property: sync removed properties to the database Tomi Ollila
2023-03-02 23:08     ` Kevin Boulain
2023-03-29 11:32       ` David Bremner
2023-03-29 16:13         ` [PATCH v2 1/5] test: display key name in property tests Kevin Boulain
2023-03-29 16:13         ` [PATCH v2 2/5] test: remove unnecessary sorting Kevin Boulain
2023-03-29 16:13         ` [PATCH v2 3/5] test: reorganize tests and mark a few of them as broken Kevin Boulain
2023-03-29 16:13         ` [PATCH v2 4/5] lib/message-property: sync removed properties to the database Kevin Boulain
2023-03-29 16:13         ` [PATCH v2 5/5] test: add test for notmuch_message_remove_all_properties_with_prefix Kevin Boulain
2023-03-30 11:25           ` David Bremner
2023-03-29 16:23         ` [PATCH 2/2] lib/message-property: sync removed properties to the database Kevin Boulain
2023-03-29 11:33       ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230301205149.297637-2-kevin@boula.in \
    --to=kevin@boula.in \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).