From aa29fae900d7535ac66ffed4c5cee58bf3301a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lie=20DELHAIE?= Date: Sun, 10 Aug 2025 12:34:08 +0200 Subject: [PATCH] fix windows sync --- cmd/cli/commands/sync/sync.go | 2 +- pkg/remote/client/client.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/cli/commands/sync/sync.go b/cmd/cli/commands/sync/sync.go index ad26bed..bc3bd91 100644 --- a/cmd/cli/commands/sync/sync.go +++ b/cmd/cli/commands/sync/sync.go @@ -264,7 +264,7 @@ func (p *SyncCmd) pullBackup(m repository.Metadata, cli *client.Client) error { return err } - if linfo != rinfo { + if linfo.MD5 != rinfo.MD5 { if err := p.Service.PullBackup(m.ID, uuid, cli); err != nil { return err } diff --git a/pkg/remote/client/client.go b/pkg/remote/client/client.go index c161939..83a741d 100644 --- a/pkg/remote/client/client.go +++ b/pkg/remote/client/client.go @@ -276,15 +276,16 @@ func (c *Client) PullBackup(gameID, uuid, archivePath string) error { if err != nil { return fmt.Errorf("failed to open file: %w", err) } - defer f.Close() res, err := cli.Do(req) if err != nil { + f.Close() return fmt.Errorf("cannot connect to remote: %w", err) } defer res.Body.Close() if res.StatusCode != http.StatusOK { + f.Close() return fmt.Errorf("cannot connect to remote: server return code: %s", res.Status) } @@ -295,8 +296,10 @@ func (c *Client) PullBackup(gameID, uuid, archivePath string) error { defer bar.Close() if _, err := io.Copy(io.MultiWriter(f, bar), res.Body); err != nil { + f.Close() return fmt.Errorf("an error occured while copying the file from the remote: %w", err) } + f.Close() if err := os.Rename(archivePath+".part", archivePath); err != nil { return fmt.Errorf("failed to move temporary data: %w", err)