target/queue: Do not attempt to do atomic overwrite for metadata on Windows

This works only on Unix-like systems. :(

See #334.
This commit is contained in:
fox.cpp 2021-03-07 17:36:55 +03:00
parent b494965da2
commit a69c409f94
No known key found for this signature in database
GPG key ID: 5B991F6215D2FCC0

View file

@ -67,6 +67,7 @@ import (
"math"
"os"
"path/filepath"
"runtime"
"runtime/debug"
"runtime/trace"
"strconv"
@ -767,9 +768,19 @@ func (q *Queue) storeNewMessage(meta *QueueMetadata, header textproto.Header, bo
func (q *Queue) updateMetadataOnDisk(meta *QueueMetadata) error {
metaPath := filepath.Join(q.location, meta.MsgMeta.ID+".meta")
file, err := os.Create(metaPath + ".new")
if err != nil {
return err
var file *os.File
var err error
if runtime.GOOS == "windows" {
file, err = os.Create(metaPath)
if err != nil {
return err
}
} else {
file, err = os.Create(metaPath + ".new")
if err != nil {
return err
}
}
defer file.Close()
@ -785,8 +796,10 @@ func (q *Queue) updateMetadataOnDisk(meta *QueueMetadata) error {
return err
}
if err := os.Rename(metaPath+".new", metaPath); err != nil {
return err
if runtime.GOOS != "windows" {
if err := os.Rename(metaPath+".new", metaPath); err != nil {
return err
}
}
return nil