0.0.4 #4
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user