Skip to content

Commit

Permalink
Unified error handling style (dragonflyoss#302)
Browse files Browse the repository at this point in the history
Signed-off-by: yxxhero <[email protected]>
  • Loading branch information
yxxhero authored Jun 9, 2021
1 parent 520dfcf commit d769b72
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions client/dfget/dfget.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func Download(cfg *config.DfgetConfig, client dfclient.DaemonClient) error {
logger.Errorf("download by dragonfly error: %s", err)
return downloadFromSource(cfg, hdr)
}
return err
return nil
}

func downloadFromSource(cfg *config.DfgetConfig, hdr map[string]string) (err error) {
Expand Down Expand Up @@ -161,21 +161,21 @@ func downloadFromSource(cfg *config.DfgetConfig, hdr map[string]string) (err err
}

written, err = io.Copy(target, response)
if err == nil {
logger.Infof("copied %d bytes to %s", written, cfg.Output)
end = time.Now()
fmt.Printf("Download from source success, time cost: %dms\n", end.Sub(start).Milliseconds())
// change permission
logger.Infof("change own to uid %d gid %d", basic.UserID, basic.UserGroup)
if err = os.Chown(cfg.Output, basic.UserID, basic.UserGroup); err != nil {
logger.Errorf("change own failed: %s", err)
return err
}
return nil
if err != nil {
logger.Errorf("copied %d bytes to %s, with error: %s", written, cfg.Output, err)
return err
}
logger.Infof("copied %d bytes to %s", written, cfg.Output)
end = time.Now()
fmt.Printf("Download from source success, time cost: %dms\n", end.Sub(start).Milliseconds())

// change permission
logger.Infof("change own to uid %d gid %d", basic.UserID, basic.UserGroup)
if err = os.Chown(cfg.Output, basic.UserID, basic.UserGroup); err != nil {
logger.Errorf("change own failed: %s", err)
return err
}
logger.Errorf("copied %d bytes to %s, with error: %s",
written, cfg.Output, err)
return err
return nil
}

func parseHeader(s []string) map[string]string {
Expand Down

0 comments on commit d769b72

Please sign in to comment.