Revert "Truncate config files when resaving."

This commit is contained in:
knoxfighter 2021-10-19 21:22:02 +02:00 committed by GitHub
parent 5d11bb00f7
commit 2981534587
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,15 +4,14 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"github.com/gorilla/securecookie"
"github.com/jessevdk/go-flags"
"log"
"math/rand"
"os"
"path/filepath"
"runtime"
"time"
"github.com/gorilla/securecookie"
"github.com/jessevdk/go-flags"
)
type Flags struct {
@ -60,7 +59,7 @@ type Config struct {
GlibcLibLoc string `json:"-"`
Autostart string `json:"-"`
ConsoleCacheSize int `json:"console_cache_size,omitempty"` // the amount of cached lines, inside the factorio output cache
Secure bool `json:"secure"` // set to `false` to use this tool without SSL/TLS (Default: `true`)
Secure bool `json:"secure"` // set to `false` to use this tool without SSL/TLS (Default: `true`)
}
// set Configs default values. JSON unmarshal will replace when it found something different
@ -89,7 +88,7 @@ func GetConfig() Config {
}
func (config *Config) updateConfigFile() {
file, err := os.Open(config.ConfFile)
file, err := os.OpenFile(config.ConfFile, os.O_RDONLY, 0)
failOnError(err, "Error opening file")
defer file.Close()
@ -139,7 +138,7 @@ func (config *Config) updateConfigFile() {
if resave {
// save json file again
file, err = os.Create(config.ConfFile)
file, err = os.OpenFile(config.ConfFile, os.O_WRONLY, 0)
failOnError(err, "Error opening file for writing")
defer file.Close()
@ -157,7 +156,7 @@ func (config *Config) loadServerConfig() {
// load and potentially update conf.json
config.updateConfigFile()
file, err := os.Open(config.ConfFile)
file, err := os.OpenFile(config.ConfFile, os.O_RDWR, 0)
failOnError(err, "Error loading config file.")
defer file.Close()