mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-23 15:37:01 +00:00
queue: Sync the files written on Put
When we put something in the queue and respond "250 ok" to the client, that is taken as accepting the email. As part of putting something in the queue, we write it to disk, but today we don't do an fsync on that file. That leaves a gap where a badly timed crash on some systems could lead to the file being empty, causing us to lose an email that we accepted. To elliminate (or drastically reduce on some filesystems) the chances of that situation, we call fsync on the file that gets written when we put something in the queue. Thanks to nolanl@github for reporting this in https://github.com/albertito/chasquid/issues/78.
This commit is contained in:
@@ -33,13 +33,13 @@ func ReadTextMessage(fname string, pb proto.Message) error {
|
||||
}
|
||||
|
||||
// WriteMessage marshals pb and atomically writes it into fname.
|
||||
func WriteMessage(fname string, pb proto.Message, perm os.FileMode) error {
|
||||
func WriteMessage(fname string, pb proto.Message, perm os.FileMode, ops ...safeio.FileOp) error {
|
||||
out, err := proto.Marshal(pb)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return safeio.WriteFile(fname, out, perm)
|
||||
return safeio.WriteFile(fname, out, perm, ops...)
|
||||
}
|
||||
|
||||
var textOpts = prototext.MarshalOptions{
|
||||
@@ -48,12 +48,12 @@ var textOpts = prototext.MarshalOptions{
|
||||
|
||||
// WriteTextMessage marshals pb in text format and atomically writes it into
|
||||
// fname.
|
||||
func WriteTextMessage(fname string, pb proto.Message, perm os.FileMode) error {
|
||||
func WriteTextMessage(fname string, pb proto.Message, perm os.FileMode, ops ...safeio.FileOp) error {
|
||||
out, err := textOpts.Marshal(pb)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return safeio.WriteFile(fname, out, perm)
|
||||
return safeio.WriteFile(fname, out, perm, ops...)
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user