[PATCH 2/2] [RFC] possible solution for "Race condition for '*' command"

Pieter Praet pieter at praet.org
Thu Jun 30 09:08:28 PDT 2011


`notmuch-search-operate-all' may cause a race condition because
repeatedly running `notmuch-tag' with the *original* query string
makes the result list a moving target.

One approach to resolving this, is to feed `notmuch-tag' a static result
list based on the original query string, instead of the latter itself.

See discussion @ id:"86d3i1d06r.fsf at dragonfly.greenrd.org"

Signed-off-by: Pieter Praet <pieter at praet.org>
---

Carl,

I've gone along a different route which assures only matched messages
are touched, but it does come with quite a performance hit.

Since there isn't a test for the actual race condition(s), I can't be
sure, but theoretically, at least one of them should be fixed now.

Peace

 emacs/notmuch.el |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index f11ec24..84c3ee6 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -845,7 +845,8 @@ Each character of the tag name may consist of alphanumeric
 characters as well as `_.+-'.
 "
   (interactive "sOperation (+add -drop): notmuch tag ")
-  (let ((action-split (split-string action " +")))
+  (let ((action-split (split-string action " +"))
+        (query notmuch-search-query-string))
     ;; Perform some validation
     (let ((words action-split))
       (when (null words) (error "No operation given"))
@@ -853,7 +854,13 @@ characters as well as `_.+-'.
 	(unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words))
 	  (error "Action must be of the form `+thistag -that_tag'"))
 	(setq words (cdr words))))
-    (apply 'notmuch-tag notmuch-search-query-string action-split)))
+    (dolist (msgid
+            (split-string
+              (with-output-to-string
+                (with-current-buffer standard-output
+                  (apply 'call-process notmuch-command nil t nil "search" "--output=messages" (list query))))
+            "\n+" t))
+            (apply 'notmuch-tag msgid action-split))))
 
 (defun notmuch-search-buffer-title (query)
   "Returns the title for a buffer with notmuch search results."
-- 
1.7.4.1



More information about the notmuch mailing list