@@ -10,11 +10,10 @@ import (
1010 "strings"
1111
1212 "github.com/go-kit/log"
13-
1413 "github.com/meltwater/drone-cache/internal"
1514)
1615
17- const defaultDirPermission = 0755
16+ const defaultDirPermission = 0o755
1817
1918var (
2019 // ErrSourceNotReachable means that given source is not reachable.
@@ -57,7 +56,7 @@ func (a *Archive) Create(srcs []string, w io.Writer) (int64, error) {
5756 return written , nil
5857}
5958
60- // nolint: lll
59+ // nolint: lll, cyclop
6160func writeToArchive (tw * tar.Writer , root string , skipSymlinks bool , written * int64 ) func (string , os.FileInfo , error ) error {
6261 return func (path string , fi os.FileInfo , err error ) error {
6362 if err != nil {
@@ -146,7 +145,7 @@ func createSymlinkHeader(fi os.FileInfo, path string) (*tar.Header, error) {
146145 return h , nil
147146}
148147
149- func writeFileToArchive (tw io.Writer , path string ) (n int64 , err error ) {
148+ func writeFileToArchive (tw io.Writer , path string ) (int64 , error ) {
150149 f , err := os .Open (path )
151150 if err != nil {
152151 return 0 , fmt .Errorf ("open file <%s>, %w" , path , err )
@@ -163,6 +162,7 @@ func writeFileToArchive(tw io.Writer, path string) (n int64, err error) {
163162}
164163
165164// Extract reads content from the given archive reader and restores it to the destination, returns written bytes.
165+ // nolint: cyclop
166166func (a * Archive ) Extract (dst string , r io.Reader ) (int64 , error ) {
167167 var (
168168 written int64
@@ -173,7 +173,7 @@ func (a *Archive) Extract(dst string, r io.Reader) (int64, error) {
173173 h , err := tr .Next ()
174174
175175 switch {
176- case err == io .EOF : // if no more files are found return
176+ case errors . Is ( err , io .EOF ) : // if no more files are found return
177177 return written , nil
178178 case err != nil : // return any other error
179179 return written , fmt .Errorf ("tar reader <%v>, %w" , err , ErrArchiveNotReadable )
@@ -241,7 +241,7 @@ func extractDir(h *tar.Header, target string) error {
241241 return nil
242242}
243243
244- func extractRegular (h * tar.Header , tr io.Reader , target string ) (n int64 , err error ) {
244+ func extractRegular (h * tar.Header , tr io.Reader , target string ) (int64 , error ) {
245245 f , err := os .OpenFile (target , os .O_CREATE | os .O_RDWR , os .FileMode (h .Mode ))
246246 if err != nil {
247247 return 0 , fmt .Errorf ("open extracted file for writing <%s>, %w" , target , err )
@@ -282,9 +282,8 @@ func extractLink(h *tar.Header, target string) error {
282282}
283283
284284func unlink (path string ) error {
285- _ , err := os .Lstat (path )
286- if err == nil {
287- return os .Remove (path )
285+ if _ , err := os .Lstat (path ); err == nil {
286+ return fmt .Errorf ("error with unlinking: %w" , os .Remove (path ))
288287 }
289288
290289 return nil
0 commit comments