[PATCH v2 16/16] email-lda: process all series directories at the end

Artem Bityutskiy dedekind1 at gmail.com
Fri Feb 7 02:34:20 PST 2014

On Fri, 2014-02-07 at 10:50 +0200, Artem Bityutskiy wrote:
> From: Jacob Keller <jacob.e.keller at intel.com>

Re-sending this one. I forgot to remove debugging prints, and here is
the corrected version. Sorry.

>From bde5334f97ed3680f002ee472d336d36a63de06f Mon Sep 17 00:00:00 2001
From: Jacob Keller <jacob.e.keller at intel.com>
Date: Thu, 9 Jan 2014 15:28:37 -0800
Subject: [PATCH 16/16] email-lda: process all series directories at the end

Sometimes the email-lda program can misbehave and a series could end up
becoming "complete" but the LDA does not queue it when the last patch was
added. This patch modifies the LDA so that it will check all series at the end
of each mail and queue them, rather than only checking a series when some
thing is added.

The primary benefit of this is if a series does not properly get queued, the
administrator can come in and manually add the patches to the series
directory. Then the series will properly be "queued" after the next email
triggers the LDA.

This does come at a slight hit in terms of performance as we now have to check
whether series are complete for every email. However, the gain in being able
to easily fixup and get a series queued again when errors occur is much more

Artem: this patch did not really work properly, because it was missing the
"series_is_complete" check. I also did some re-factoring, and tested the final
version. Seems to work fine. I also got rid of bash-only constructs.

Signed-off-by: Jacob Keller <jacob.e.keller at intel.com>
 email/aiaiai-email-lda | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/email/aiaiai-email-lda b/email/aiaiai-email-lda
index 41de6fb..7489ffe 100755
--- a/email/aiaiai-email-lda
+++ b/email/aiaiai-email-lda
@@ -123,6 +123,9 @@ reject_and_reply()
 # the current date (taken from the global $date variable), <suffix> is the
 # a suffix supplied by the caller via "$2", and <counter> is usually 0, but if
 # there is already a file with such name, it gets increased to 1, and so on.
+# NOTE! The 'process_all_series()' function relies on this directory name
+# format, so do not forget to amend the function if you change the format.
 	local where="$1"; shift
@@ -411,6 +414,44 @@ process_mbox()
+# This function goes through all the incomplete path series which we have
+# collected so far. And if the series happens to be complete, it queues them.
+# Normally, there should be no complete series in the "$series" directory.
+# However, sometimes this script misbehaves due to some bugs, and fails to add
+# a patch to the series, so it never gets queued. Then the Aiaiai admin may do
+# this manually. However, the series does not get queued anyway, because this
+# scrpt only checks the series when it adds a patch there.
+# And this is where this function comes handy. It will go through the series
+# and queue all the complete ones.
+# The only parameter of this function is the file to use as a temporary storage
+# for mboxes.
+	local mbox="$1"; shift
+	local dir n
+	separator
+	message "Going through all partial series and checking if some of them became complete"
+	# Get all the current series
+	printf "%s\n" "$(find "$series" -mindepth 1 -maxdepth 1 -type d)" | \
+	    while IFS= read -r dir; do
+		[ -n "$dir" ] || continue
+		# Extract the series number
+		n=${dir%-*}
+		n=${n##*_}
+		# Clear everything from the current mbox
+		truncate -s0 -- "$mbox"
+		if series_is_complete "$dir" "$n"; then
+			queue_series "$mbox" "$dir" "$n"
+		fi
+	done
 	local dir="$1"; shift
@@ -539,6 +580,8 @@ done
 printf "%s\n" "$prev" >> "$mbox"
 process_mbox "$mbox"
+process_all_series "$mbox"
 [ -z "$incomplete_min" ] || reap_old "$lda_tmp" "$incomplete_min"
 [ -z "$archive_min" ] || reap_old "$mail" "$archive_min"
 [ -z "$archive_min" ] || reap_old "$queue_saved" "$archive_min"

Best Regards,
Artem Bityutskiy

More information about the aiaiai mailing list