diff --git a/ludos/connman.go b/ludos/connman.go index 287e7b99..b0faec00 100644 --- a/ludos/connman.go +++ b/ludos/connman.go @@ -97,11 +97,18 @@ IPv4.method=dhcp return err } defer fd.Close() + _, err = fd.WriteString(config) if err != nil { return err } + // We want the sync to happen before connmanctl connect, don't defer + err = fd.Sync() + if err != nil { + return err + } + err = exec.Command("/usr/bin/connmanctl", "connect", network.Path).Run() if err != nil { return err diff --git a/main.go b/main.go index 548241c5..41de8d66 100644 --- a/main.go +++ b/main.go @@ -126,5 +126,5 @@ func main() { runLoop(vid, m) // Unload and deinit in the core. - core.UnloadGame() + core.Unload() } diff --git a/menu/scene_core_options.go b/menu/scene_core_options.go index b4da1750..e8dac5f6 100644 --- a/menu/scene_core_options.go +++ b/menu/scene_core_options.go @@ -4,6 +4,7 @@ import ( "strings" "github.com/libretro/ludo/core" + ntf "github.com/libretro/ludo/notifications" "github.com/libretro/ludo/state" "github.com/libretro/ludo/video" ) @@ -34,7 +35,10 @@ func buildCoreOptions() Scene { core.Options.Choices[i] = 0 } core.Options.Updated = true - core.Options.Save() + err := core.Options.Save() + if err != nil { + ntf.DisplayAndLog(ntf.Error, "Core", "Error saving core options: %v", err.Error()) + } }, }) } diff --git a/options/options.go b/options/options.go index 53822ba0..79c56785 100644 --- a/options/options.go +++ b/options/options.go @@ -62,13 +62,18 @@ func (o *Options) Save() error { } name := utils.FileName(state.Global.CorePath) - f, err := os.Create(filepath.Join(usr.HomeDir, ".ludo", name+".json")) + fd, err := os.Create(filepath.Join(usr.HomeDir, ".ludo", name+".json")) if err != nil { return err } - defer f.Close() - _, err = io.Copy(f, bytes.NewReader(b)) - return err + defer fd.Close() + + _, err = io.Copy(fd, bytes.NewReader(b)) + if err != nil { + return err + } + + return fd.Sync() } // Load core options from a file @@ -89,6 +94,9 @@ func (o *Options) load() error { var opts map[string]string err = json.Unmarshal(b, &opts) + if err != nil { + return err + } for optk, optv := range opts { for i, variable := range o.Vars { @@ -102,5 +110,5 @@ func (o *Options) load() error { } } - return err + return nil } diff --git a/savefiles/savefiles.go b/savefiles/savefiles.go index 3a8fd759..fd9fbfe8 100644 --- a/savefiles/savefiles.go +++ b/savefiles/savefiles.go @@ -55,10 +55,19 @@ func SaveSRAM() error { if err != nil { return err } - defer fd.Close() - fd.Write(bytes) - return nil + _, err = fd.Write(bytes) + if err != nil { + fd.Close() + return err + } + + err = fd.Close() + if err != nil { + return err + } + + return fd.Sync() } // LoadSRAM saves the game SRAM to the filesystem diff --git a/settings/settings.go b/settings/settings.go index e2576dd0..00c2fcf4 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -104,14 +104,18 @@ func Save() error { return err } - f, err := os.Create(filepath.Join(usr.HomeDir, ".ludo", "settings.json")) + fd, err := os.Create(filepath.Join(usr.HomeDir, ".ludo", "settings.json")) if err != nil { return err } - defer f.Close() + defer fd.Close() - _, err = io.Copy(f, bytes.NewReader(b)) - return err + _, err = io.Copy(fd, bytes.NewReader(b)) + if err != nil { + return err + } + + return fd.Sync() } // CoreForPlaylist returns the absolute path of the default libretro core for