Skip to content

Commit 3dc1ee6

Browse files
committed
handle sync errors
- syncandnotify() aborts early if mbsync or mpop fails - mailsync aborts early (exit code 1, before notmuch) if all syncs fail
1 parent b7b7f21 commit 3dc1ee6

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

‎bin/mailsync‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ syncandnotify() {
5858
case "$1" in
5959
imap) mbsync -q "$2" ;;
6060
pop) mpop -q "$2" ;;
61-
esac
61+
esac || return 1
6262
new=$(find\
6363
"$HOME/.local/share/mail/$2/"[Ii][Nn][Bb][Oo][Xx]/new/ \
6464
"$HOME/.local/share/mail/$2/"[Ii][Nn][Bb][Oo][Xx]/cur/ \
@@ -100,15 +100,34 @@ else
100100
done || echo "error $arg"; done)"
101101
fi
102102
103+
pids= # PIDs of backgrounded subshells
104+
count=0 # number of accounts in $tosync
105+
failed=0 # number of failed sync attempts
103106
for account in $tosync; do
107+
count=$((count+1))
104108
case $account in
105-
Channel*) syncandnotify imap "${account##* }" & ;;
106-
account*) syncandnotify pop "${account##* }" & ;;
107-
error*) echo "ERROR: Account ${account##* } not found." ;;
109+
Channel*)
110+
syncandnotify imap "${account##* }" &
111+
pids="$pids $!"
112+
;;
113+
account*)
114+
syncandnotify pop "${account##* }" &
115+
pids="$pids $!"
116+
;;
117+
error*)
118+
echo "ERROR: Account ${account##* } not found."
119+
failed=$((failed+1))
120+
;;
108121
esac
109122
done
110123
111-
wait
124+
IFS=' '
125+
for pid in $pids; do
126+
wait $pid || failed=$((failed+1))
127+
done
128+
129+
# Abort if no account sync succeeded
130+
[ "$count" -gt "$failed" ] || exit 1
112131
113132
notmuch new --quiet
114133

0 commit comments

Comments
 (0)