From e1054bd81602c1592c8e3ccd6a671a75898d6329 Mon Sep 17 00:00:00 2001 From: majormjr Date: Tue, 11 Oct 2016 11:15:55 -0400 Subject: [PATCH] Moved createSave function to saves.go, changed permissions when creating server-settings.json file to remove executable permissions --- src/factorio_server.go | 21 +-------------------- src/saves.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/factorio_server.go b/src/factorio_server.go index 819386e..a948a6a 100644 --- a/src/factorio_server.go +++ b/src/factorio_server.go @@ -46,25 +46,6 @@ type FactorioServerSettings struct { Admins []string `json:"admins"` } -func createSave(filePath string) (string, error) { - err := os.MkdirAll(filepath.Base(filePath), 0755) - if err != nil { - log.Printf("Error in creating Factorio save: %s", err) - return "", err - } - - args := []string{"--create", filePath} - cmdOutput, err := exec.Command(config.FactorioBinary, args...).Output() - if err != nil { - log.Printf("Error in creating Factorio save: %s", err) - return "", err - } - - result := string(cmdOutput) - - return result, nil -} - func initFactorio() *FactorioServer { f := FactorioServer{} @@ -101,7 +82,7 @@ func (f *FactorioServer) Run() error { if err != nil { log.Println("Failed to marshal FactorioServerSettings: ", err) } else { - ioutil.WriteFile(filepath.Join(config.FactorioDir, "server-settings.json"), data, 0755) + ioutil.WriteFile(filepath.Join(config.FactorioDir, "server-settings.json"), data, 0644) } args := []string{ diff --git a/src/saves.go b/src/saves.go index 84e27f6..eb35ed1 100644 --- a/src/saves.go +++ b/src/saves.go @@ -3,7 +3,9 @@ package main import ( "errors" "fmt" + "log" "os" + "os/exec" "path/filepath" "time" ) @@ -53,3 +55,23 @@ func (s *Save) remove() error { return os.Remove(filepath.Join(config.FactorioSavesDir, s.Name)) } + +// Create savefiles for Factorio +func createSave(filePath string) (string, error) { + err := os.MkdirAll(filepath.Base(filePath), 0755) + if err != nil { + log.Printf("Error in creating Factorio save: %s", err) + return "", err + } + + args := []string{"--create", filePath} + cmdOutput, err := exec.Command(config.FactorioBinary, args...).Output() + if err != nil { + log.Printf("Error in creating Factorio save: %s", err) + return "", err + } + + result := string(cmdOutput) + + return result, nil +}