Merge PR #17: freezer_windows: make ReplaceFile call fall back to os.Rename.

This commit is contained in:
Mikkel Krautz 2018-01-13 21:42:17 +01:00 committed by GitHub
commit ff93fc4868
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
}