Moved createSave function to saves.go, changed permissions when creating server-settings.json file to remove executable permissions

This commit is contained in:
majormjr 2016-10-11 11:15:55 -04:00
parent 2e1945014b
commit e1054bd816
2 changed files with 23 additions and 20 deletions

View File

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

View File

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