Skip to content

Commit 691e924

Browse files
author
Mitch Roote
authored
Merge pull request #49 from bostelk/patch-10
Fix create save file
2 parents 8d4355c + 86d2cd9 commit 691e924

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/handlers.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,8 @@ func CreateSaveHandler(w http.ResponseWriter, r *http.Request) {
462462
return
463463
}
464464

465-
cmdOut, err := createSave(saveName)
465+
saveFile := filepath.Join(config.FactorioSavesDir, saveName)
466+
cmdOut, err := createSave(saveFile)
466467
if err != nil {
467468
log.Printf("Error creating save: %s", err)
468469
resp.Data = "Error creating savefile."

src/server.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ type FactorioServer struct {
2626
StdIn io.WriteCloser
2727
}
2828

29-
func createSave(saveName string) (string, error) {
30-
args := []string{"--create", saveName}
29+
func createSave(filePath string) (string, error) {
30+
err := os.MkdirAll(filepath.Base(filePath), 0755)
31+
if err != nil {
32+
log.Printf("Error in creating Factorio save: %s", err)
33+
return "", err
34+
}
3135

36+
args := []string{"--create", filePath}
3237
cmdOutput, err := exec.Command(config.FactorioBinary, args...).Output()
3338
if err != nil {
3439
log.Printf("Error in creating Factorio save: %s", err)

0 commit comments

Comments
 (0)