]> www.infradead.org Git - users/dedekind/aiaiai.git/commitdiff
email-lda: process all series directories at the end
authorJacob Keller <jacob.e.keller@intel.com>
Thu, 9 Jan 2014 23:28:37 +0000 (15:28 -0800)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Fri, 7 Feb 2014 08:56:26 +0000 (10:56 +0200)
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
useful.

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@intel.com>
email/aiaiai-email-lda

index 41de6fb357cd7abfda67d8ff04f6aa820e63a955..7489ffe853494c0af40676fe44e2240618d048d5 100755 (executable)
@@ -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.
 generate_file_name()
 {
        local where="$1"; shift
@@ -411,6 +414,44 @@ process_mbox()
        fi
 }
 
+# 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.
+process_all_series()
+{
+       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
+}
+
 reap_old()
 {
        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"