@@ -260,7 +260,7 @@ func (r *bufferedReader) Read(p []byte) (int, error) {
260260 return 0 , io .EOF
261261 }
262262 n , err := r .buf .Read (p )
263- if err == io .EOF {
263+ if errors . Is ( err , io .EOF ) {
264264 r .buf .Reset (nil )
265265 bufioReader32KPool .Put (r .buf )
266266 r .buf = nil
@@ -279,7 +279,7 @@ func (r *bufferedReader) Peek(n int) ([]byte, error) {
279279func DecompressStream (archive io.Reader ) (io.ReadCloser , error ) {
280280 buf := newBufferedReader (archive )
281281 bs , err := buf .Peek (10 )
282- if err != nil && err != io .EOF {
282+ if err != nil && ! errors . Is ( err , io .EOF ) {
283283 // Note: we'll ignore any io.EOF error because there are some odd
284284 // cases where the layer.tar file will be empty (zero bytes) and
285285 // that results in an io.EOF from the Peek() call. So, in those
@@ -344,7 +344,7 @@ func DecompressStream(archive io.Reader) (io.ReadCloser, error) {
344344 },
345345 }, nil
346346 default :
347- return nil , fmt .Errorf ("Unsupported compression format %s" , (& compression ).Extension ())
347+ return nil , fmt .Errorf ("unsupported compression format: %s" , (& compression ).Extension ())
348348 }
349349}
350350
@@ -364,9 +364,9 @@ func CompressStream(dest io.Writer, compression Compression) (io.WriteCloser, er
364364 case Bzip2 , Xz :
365365 // archive/bzip2 does not support writing, and there is no xz support at all
366366 // However, this is not a problem as docker only currently generates gzipped tars
367- return nil , fmt .Errorf ("Unsupported compression format %s" , (& compression ).Extension ())
367+ return nil , fmt .Errorf ("unsupported compression format: %s" , (& compression ).Extension ())
368368 default :
369- return nil , fmt .Errorf ("Unsupported compression format %s" , (& compression ).Extension ())
369+ return nil , fmt .Errorf ("unsupported compression format: %s" , (& compression ).Extension ())
370370 }
371371}
372372
@@ -416,7 +416,7 @@ func ReplaceFileTarWrapper(inputTarStream io.ReadCloser, mods map[string]TarModi
416416 var originalHeader * tar.Header
417417 for {
418418 originalHeader , err = tarReader .Next ()
419- if err == io .EOF {
419+ if errors . Is ( err , io .EOF ) {
420420 break
421421 }
422422 if err != nil {
@@ -768,7 +768,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, o
768768 case tar .TypeDir :
769769 // Create directory unless it exists as a directory already.
770770 // In that case we just want to merge the two
771- if fi , err := os .Lstat (path ); ! ( err == nil && fi .IsDir () ) {
771+ if fi , err := os .Lstat (path ); err != nil || ! fi .IsDir () {
772772 if err := os .Mkdir (path , hdrInfo .Mode ()); err != nil {
773773 return err
774774 }
@@ -1031,7 +1031,8 @@ func (t *Tarballer) Do() {
10311031 )
10321032
10331033 walkRoot := getWalkRoot (t .srcPath , include )
1034- filepath .WalkDir (walkRoot , func (filePath string , f os.DirEntry , err error ) error {
1034+ // TODO(thaJeztah): should this error be handled?
1035+ _ = filepath .WalkDir (walkRoot , func (filePath string , f os.DirEntry , err error ) error {
10351036 if err != nil {
10361037 log .G (context .TODO ()).Errorf ("Tar: Can't stat file %s to tar: %s" , t .srcPath , err )
10371038 return nil
@@ -1135,7 +1136,7 @@ func (t *Tarballer) Do() {
11351136 if err := ta .addTarFile (filePath , relFilePath ); err != nil {
11361137 log .G (context .TODO ()).Errorf ("Can't add file %s to tar: %s" , filePath , err )
11371138 // if pipe is broken, stop writing tar stream to it
1138- if err == io .ErrClosedPipe {
1139+ if errors . Is ( err , io .ErrClosedPipe ) {
11391140 return err
11401141 }
11411142 }
@@ -1155,7 +1156,7 @@ func Unpack(decompressedArchive io.Reader, dest string, options *TarOptions) err
11551156loop:
11561157 for {
11571158 hdr , err := tr .Next ()
1158- if err == io .EOF {
1159+ if errors . Is ( err , io .EOF ) {
11591160 // end of tar archive
11601161 break
11611162 }
@@ -1217,7 +1218,7 @@ loop:
12171218 continue
12181219 }
12191220
1220- if ! ( fi .IsDir () && hdr .Typeflag == tar .TypeDir ) {
1221+ if ! fi .IsDir () || hdr .Typeflag != tar .TypeDir {
12211222 if err := os .RemoveAll (path ); err != nil {
12221223 return err
12231224 }
@@ -1309,7 +1310,7 @@ func UntarUncompressed(tarArchive io.Reader, dest string, options *TarOptions) e
13091310// Handler for teasing out the automatic decompression
13101311func untarHandler (tarArchive io.Reader , dest string , options * TarOptions , decompress bool ) error {
13111312 if tarArchive == nil {
1312- return fmt . Errorf ( "Empty archive" )
1313+ return errors . New ( "empty archive" )
13131314 }
13141315 dest = filepath .Clean (dest )
13151316 if options == nil {
@@ -1393,7 +1394,7 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
13931394 }
13941395
13951396 if srcSt .IsDir () {
1396- return fmt . Errorf ( "Can 't copy a directory" )
1397+ return errors . New ( "can 't copy a directory" )
13971398 }
13981399
13991400 // Clean up the trailing slash. This must be done in an operating
@@ -1492,9 +1493,9 @@ func cmdStream(cmd *exec.Cmd, input io.Reader) (io.ReadCloser, error) {
14921493 // Copy stdout to the returned pipe
14931494 go func () {
14941495 if err := cmd .Wait (); err != nil {
1495- pipeW .CloseWithError (fmt .Errorf ("%s : %s" , err , errBuf .String ()))
1496+ _ = pipeW .CloseWithError (fmt .Errorf ("%w : %s" , err , errBuf .String ()))
14961497 } else {
1497- pipeW .Close ()
1498+ _ = pipeW .Close ()
14981499 }
14991500 close (done )
15001501 }()
0 commit comments