diff --git a/download/download.go b/download/download.go index b9c09b0..db93b36 100644 --- a/download/download.go +++ b/download/download.go @@ -14,7 +14,7 @@ import ( "github.com/ansel1/merry/v2" "golang.org/x/mod/semver" - "github.com/murfffi/getaduck/internal/sclerr" + "github.com/murfffi/gorich/helperr" ) const ( @@ -211,14 +211,17 @@ func extractFile(file *zip.File) error { if err != nil { return err } - defer sclerr.CloseQuietly(outFile) + defer helperr.CloseQuietly(outFile) fileReader, err := file.Open() if err != nil { return err } - defer sclerr.CloseQuietly(fileReader) + defer helperr.CloseQuietly(fileReader) _, err = io.Copy(outFile, fileReader) - return err + if err != nil { + return err + } + return outFile.Close() } func getEntryName(spec Spec) string { @@ -259,12 +262,12 @@ func fetchZip(url string) (string, error) { if resp.StatusCode != http.StatusOK { return "", fmt.Errorf("HTTP error when trying to download %s: %d", url, resp.StatusCode) } - defer sclerr.CloseQuietly(resp.Body) + defer helperr.CloseQuietly(resp.Body) tmpZip, err := os.CreateTemp("", "getaduck") if err != nil { return "", fmt.Errorf("failed to create temp file: %w", err) } - defer sclerr.CloseQuietly(tmpZip) + defer helperr.CloseQuietly(tmpZip) _, err = io.Copy(tmpZip, resp.Body) if err != nil { return "", genericDownloadErr(url, err) diff --git a/go.mod b/go.mod index 4877963..0f07ae9 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,9 @@ module github.com/murfffi/getaduck go 1.24.7 require ( - github.com/ansel1/merry/v2 v2.2.1 - github.com/stretchr/testify v1.8.3 + github.com/ansel1/merry/v2 v2.2.2 + github.com/murfffi/gorich v0.2.0 + github.com/stretchr/testify v1.11.1 golang.org/x/mod v0.28.0 ) diff --git a/go.sum b/go.sum index b1ca6e8..8a859f2 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,15 @@ -github.com/ansel1/merry/v2 v2.2.1 h1:PJpynLFvIpJkn8ZGgNHLq332zIyBc/wTqp3o42ZpWdU= -github.com/ansel1/merry/v2 v2.2.1/go.mod h1:K9lCkM6tJ8s7LQVQ0ZmZ0WrB3BCyr+ZDzoqotzzoxpI= +github.com/ansel1/merry/v2 v2.2.2 h1:/R8URU5LtiYwP7UI1KoZW4ex4nTzr+/T49+TYZsjUas= +github.com/ansel1/merry/v2 v2.2.2/go.mod h1:sludwzkWfhZHOF4jSOViv+t2nnu2HNmtsMKzAfwmVB8= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-errors/errors v1.1.1 h1:ljK/pL5ltg3qoN+OtN6yCv9HWSfMwxSx90GJCZQxYNg= github.com/go-errors/errors v1.1.1/go.mod h1:psDX2osz5VnTOnFWbDeWwS7yejl+uV3FEWEp4lssFEs= +github.com/murfffi/gorich v0.2.0 h1:eUQ2xzjp7czPemnc0nSEDVBLz2xyFKfQg2kSgJ9ljwk= +github.com/murfffi/gorich v0.2.0/go.mod h1:o1VsmtwZ9U/E8eyiLvhUTOdV810J8v6Y0R3pi/97TdQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= -github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U= golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= diff --git a/internal/sclerr/sclerr.go b/internal/sclerr/sclerr.go deleted file mode 100644 index 6ba3538..0000000 --- a/internal/sclerr/sclerr.go +++ /dev/null @@ -1,7 +0,0 @@ -package sclerr - -import "io" - -func CloseQuietly(c io.Closer) { - _ = c.Close() -}