fix windows sync

This commit is contained in:
2025-08-10 12:34:08 +02:00
parent 822c93bf4c
commit aa29fae900
2 changed files with 5 additions and 2 deletions

View File

@@ -264,7 +264,7 @@ func (p *SyncCmd) pullBackup(m repository.Metadata, cli *client.Client) error {
return err return err
} }
if linfo != rinfo { if linfo.MD5 != rinfo.MD5 {
if err := p.Service.PullBackup(m.ID, uuid, cli); err != nil { if err := p.Service.PullBackup(m.ID, uuid, cli); err != nil {
return err return err
} }

View File

@@ -276,15 +276,16 @@ func (c *Client) PullBackup(gameID, uuid, archivePath string) error {
if err != nil { if err != nil {
return fmt.Errorf("failed to open file: %w", err) return fmt.Errorf("failed to open file: %w", err)
} }
defer f.Close()
res, err := cli.Do(req) res, err := cli.Do(req)
if err != nil { if err != nil {
f.Close()
return fmt.Errorf("cannot connect to remote: %w", err) return fmt.Errorf("cannot connect to remote: %w", err)
} }
defer res.Body.Close() defer res.Body.Close()
if res.StatusCode != http.StatusOK { if res.StatusCode != http.StatusOK {
f.Close()
return fmt.Errorf("cannot connect to remote: server return code: %s", res.Status) 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() defer bar.Close()
if _, err := io.Copy(io.MultiWriter(f, bar), res.Body); err != nil { 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) 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 { if err := os.Rename(archivePath+".part", archivePath); err != nil {
return fmt.Errorf("failed to move temporary data: %w", err) return fmt.Errorf("failed to move temporary data: %w", err)