forked from External/grumble
Merge PR #17: freezer_windows: make ReplaceFile call fall back to os.Rename.
This commit is contained in:
commit
ff93fc4868
1 changed files with 10 additions and 2 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/golang/protobuf/proto"
|
||||
"io/ioutil"
|
||||
"mumble.info/grumble/pkg/replacefile"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
)
|
||||
|
|
@ -50,10 +51,17 @@ func (server *Server) freezeToFile() (err error) {
|
|||
src := f.Name()
|
||||
dst := filepath.Join(Args.DataDir, "servers", strconv.FormatInt(server.Id, 10), "main.fz")
|
||||
backup := filepath.Join(Args.DataDir, "servers", strconv.FormatInt(server.Id, 10), "backup.fz")
|
||||
|
||||
err = replacefile.ReplaceFile(dst, src, backup, replacefile.Flag(0))
|
||||
// If the dst file does not exist (as in, on first launch)
|
||||
// fall back to os.Rename. ReplaceFile does not work if the
|
||||
// dst file is not there.
|
||||
if os.IsNotExist(err) {
|
||||
err = os.Rename(src, dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue