Bescause the working directory is set to where the go executable is running the absolute path should be used when creating a new map.

This commit is contained in:
Kyle Bostelmann 2016-09-29 19:37:13 -03:00
parent d788b25a74
commit 86d2cd9158
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)