Merge pull request #49 from bostelk/patch-10

Fix create save file
This commit is contained in:
Mitch Roote 2016-09-30 10:56:19 -04:00 committed by GitHub
commit 691e924269
2 changed files with 9 additions and 3 deletions

View File

@ -462,7 +462,8 @@ func CreateSaveHandler(w http.ResponseWriter, r *http.Request) {
return
}
cmdOut, err := createSave(saveName)
saveFile := filepath.Join(config.FactorioSavesDir, saveName)
cmdOut, err := createSave(saveFile)
if err != nil {
log.Printf("Error creating save: %s", err)
resp.Data = "Error creating savefile."

View File

@ -26,9 +26,14 @@ type FactorioServer struct {
StdIn io.WriteCloser
}
func createSave(saveName string) (string, error) {
args := []string{"--create", saveName}
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)