From 2981534587da5555614f3887e5bcd81973da0a68 Mon Sep 17 00:00:00 2001 From: knoxfighter Date: Tue, 19 Oct 2021 21:22:02 +0200 Subject: [PATCH] Revert "Truncate config files when resaving." --- src/bootstrap/config.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/bootstrap/config.go b/src/bootstrap/config.go index 8c281a7..2424202 100644 --- a/src/bootstrap/config.go +++ b/src/bootstrap/config.go @@ -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()