From 3e53343d21f47639317a9e1d22c91da0e48a565f Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Sat, 14 Oct 2023 11:16:39 +0200 Subject: [PATCH] remove message during delivery when we encounter an error after having placed the message in the destination path before, we would leave the file, but rollback the delivery. future deliveries would attempt to deliver to the same path, but would fail because a file already exists. encountered during testing on windows, not during actual operation. though it could in theory have happened. --- store/account.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/store/account.go b/store/account.go index ad2491e..ef5104f 100644 --- a/store/account.go +++ b/store/account.go @@ -1349,6 +1349,8 @@ func (a *Account) DeliverMessage(log *mlog.Log, tx *bstore.Tx, m *Message, msgFi if sync { if err := moxio.SyncDir(msgDir); err != nil { + xerr := os.Remove(msgPath) + log.Check(xerr, "removing message after syncdir error", mlog.Field("path", msgPath)) return fmt.Errorf("sync directory: %w", err) } } @@ -1356,6 +1358,8 @@ func (a *Account) DeliverMessage(log *mlog.Log, tx *bstore.Tx, m *Message, msgFi if !notrain && m.NeedsTraining() { l := []Message{*m} if err := a.RetrainMessages(context.TODO(), log, tx, l, false); err != nil { + xerr := os.Remove(msgPath) + log.Check(xerr, "removing message after syncdir error", mlog.Field("path", msgPath)) return fmt.Errorf("training junkfilter: %w", err) } *m = l[0]