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"
|
"github.com/golang/protobuf/proto"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"mumble.info/grumble/pkg/replacefile"
|
"mumble.info/grumble/pkg/replacefile"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
@ -50,9 +51,16 @@ func (server *Server) freezeToFile() (err error) {
|
||||||
src := f.Name()
|
src := f.Name()
|
||||||
dst := filepath.Join(Args.DataDir, "servers", strconv.FormatInt(server.Id, 10), "main.fz")
|
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")
|
backup := filepath.Join(Args.DataDir, "servers", strconv.FormatInt(server.Id, 10), "backup.fz")
|
||||||
|
|
||||||
err = replacefile.ReplaceFile(dst, src, backup, replacefile.Flag(0))
|
err = replacefile.ReplaceFile(dst, src, backup, replacefile.Flag(0))
|
||||||
if err != nil {
|
// If the dst file does not exist (as in, on first launch)
|
||||||
return err
|
// 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
|
return nil
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue