Skip to content

Commit

Permalink
Remove DownloadFile func in favor of CopyFile (#1705)
Browse files Browse the repository at this point in the history
remove DownloadFile
  • Loading branch information
hellt authored Nov 7, 2023
1 parent 31220cf commit f8ad48e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 26 deletions.
2 changes: 1 addition & 1 deletion clab/clab.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (c *CLab) downloadTopoFile(url string) (string, error) {
return "", err
}

err = utils.DownloadFile(url, tmpFile.Name())
err = utils.CopyFile(url, tmpFile.Name(), 0644)

return tmpFile.Name(), err
}
Expand Down
25 changes: 0 additions & 25 deletions utils/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,28 +345,3 @@ func NewHTTPClient() *http.Client {

return &http.Client{Transport: tr}
}

// DownloadFile downloads a file from `src` url and saves it to `dst` path.
// `dst` must exist.
func DownloadFile(src, dst string) error {
client := NewHTTPClient()

resp, err := client.Get(src)
if err != nil || resp.StatusCode != 200 {
return fmt.Errorf("%w: %s", errHTTPFetch, src)
}

defer resp.Body.Close() // skipcq: GO-S2307

body, err := io.ReadAll(resp.Body)
if err != nil {
return err
}

err = os.WriteFile(dst, body, 0644)
if err != nil {
return err
}

return nil
}

0 comments on commit f8ad48e

Please sign in to comment.