Skip to content

Commit e1054bd

Browse files
committed
Moved createSave function to saves.go, changed permissions when creating server-settings.json file to remove executable permissions
1 parent 2e19450 commit e1054bd

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

src/factorio_server.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,6 @@ type FactorioServerSettings struct {
4646
Admins []string `json:"admins"`
4747
}
4848

49-
func createSave(filePath string) (string, error) {
50-
err := os.MkdirAll(filepath.Base(filePath), 0755)
51-
if err != nil {
52-
log.Printf("Error in creating Factorio save: %s", err)
53-
return "", err
54-
}
55-
56-
args := []string{"--create", filePath}
57-
cmdOutput, err := exec.Command(config.FactorioBinary, args...).Output()
58-
if err != nil {
59-
log.Printf("Error in creating Factorio save: %s", err)
60-
return "", err
61-
}
62-
63-
result := string(cmdOutput)
64-
65-
return result, nil
66-
}
67-
6849
func initFactorio() *FactorioServer {
6950
f := FactorioServer{}
7051

@@ -101,7 +82,7 @@ func (f *FactorioServer) Run() error {
10182
if err != nil {
10283
log.Println("Failed to marshal FactorioServerSettings: ", err)
10384
} else {
104-
ioutil.WriteFile(filepath.Join(config.FactorioDir, "server-settings.json"), data, 0755)
85+
ioutil.WriteFile(filepath.Join(config.FactorioDir, "server-settings.json"), data, 0644)
10586
}
10687

10788
args := []string{

src/saves.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package main
33
import (
44
"errors"
55
"fmt"
6+
"log"
67
"os"
8+
"os/exec"
79
"path/filepath"
810
"time"
911
)
@@ -53,3 +55,23 @@ func (s *Save) remove() error {
5355

5456
return os.Remove(filepath.Join(config.FactorioSavesDir, s.Name))
5557
}
58+
59+
// Create savefiles for Factorio
60+
func createSave(filePath string) (string, error) {
61+
err := os.MkdirAll(filepath.Base(filePath), 0755)
62+
if err != nil {
63+
log.Printf("Error in creating Factorio save: %s", err)
64+
return "", err
65+
}
66+
67+
args := []string{"--create", filePath}
68+
cmdOutput, err := exec.Command(config.FactorioBinary, args...).Output()
69+
if err != nil {
70+
log.Printf("Error in creating Factorio save: %s", err)
71+
return "", err
72+
}
73+
74+
result := string(cmdOutput)
75+
76+
return result, nil
77+
}

0 commit comments

Comments
 (0)