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.
This commit is contained in:
Mechiel Lukkien 2023-10-14 11:16:39 +02:00
parent 6e391c3be0
commit 3e53343d21
No known key found for this signature in database

View file

@ -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]