mirror of
https://github.com/foxcpp/maddy.git
synced 2025-04-06 22:47:37 +03:00
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:
parent
b494965da2
commit
a69c409f94
1 changed files with 18 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue