Rename and move everything to hopefully make it possible to use this package as a Golang package

This commit is contained in:
Ola Bini 2019-12-17 17:50:55 +00:00
parent 4a90b31d8d
commit 050b578821
No known key found for this signature in database
GPG key ID: 6786A150F6A2B28F
23 changed files with 74 additions and 204 deletions

58
server/freeze_unix.go Normal file
View file

@ -0,0 +1,58 @@
// Copyright (c) 2012 The Grumble Authors
// The use of this source code is goverened by a BSD-style
// license that can be found in the LICENSE-file.
// +build !windows
package server
import (
"io/ioutil"
"os"
"path/filepath"
"strconv"
"github.com/golang/protobuf/proto"
)
func (server *Server) freezeToFile() (err error) {
// Close the log file, if it's open
if server.freezelog != nil {
err = server.freezelog.Close()
if err != nil {
return err
}
}
// Make sure the whole server is synced to disk
fs, err := server.Freeze()
if err != nil {
return err
}
f, err := ioutil.TempFile(filepath.Join(Args.DataDir, "servers", strconv.FormatInt(server.Id, 10)), ".main.fz_")
if err != nil {
return err
}
buf, err := proto.Marshal(fs)
if err != nil {
return err
}
_, err = f.Write(buf)
if err != nil {
return err
}
err = f.Sync()
if err != nil {
return err
}
err = f.Close()
if err != nil {
return err
}
err = os.Rename(f.Name(), filepath.Join(Args.DataDir, "servers", strconv.FormatInt(server.Id, 10), "main.fz"))
if err != nil {
return err
}
return nil
}