@@ -80,7 +80,7 @@ func ValidateContextDirectory(srcPath string, excludes []string) error {
8080 if err != nil && os .IsPermission (err ) {
8181 return errors .Errorf ("no permission to read from '%s'" , filePath )
8282 }
83- currentFile .Close ()
83+ _ = currentFile .Close ()
8484 }
8585 return nil
8686 })
@@ -97,18 +97,18 @@ func filepathMatches(matcher *patternmatcher.PatternMatcher, file string) (bool,
9797
9898// DetectArchiveReader detects whether the input stream is an archive or a
9999// Dockerfile and returns a buffered version of input, safe to consume in lieu
100- // of input. If an archive is detected, isArchive is set to true, and to false
100+ // of input. If an archive is detected, ok is set to true, and to false
101101// otherwise, in which case it is safe to assume input represents the contents
102102// of a Dockerfile.
103- func DetectArchiveReader (input io.ReadCloser ) (rc io.ReadCloser , isArchive bool , err error ) {
103+ func DetectArchiveReader (input io.ReadCloser ) (rc io.ReadCloser , ok bool , err error ) {
104104 buf := bufio .NewReader (input )
105105
106106 magic , err := buf .Peek (archiveHeaderSize * 2 )
107107 if err != nil && err != io .EOF {
108108 return nil , false , errors .Errorf ("failed to peek context header from STDIN: %v" , err )
109109 }
110110
111- return newReadCloserWrapper (buf , func () error { return input .Close () }), IsArchive (magic ), nil
111+ return newReadCloserWrapper (buf , func () error { return input .Close () }), isArchive (magic ), nil
112112}
113113
114114// WriteTempDockerfile writes a Dockerfile stream to a temporary file with a
@@ -141,12 +141,12 @@ func WriteTempDockerfile(rc io.ReadCloser) (dockerfileDir string, err error) {
141141// Dockerfile or tar archive. Returns a tar archive used as a context and a
142142// path to the Dockerfile inside the tar.
143143func GetContextFromReader (rc io.ReadCloser , dockerfileName string ) (out io.ReadCloser , relDockerfile string , err error ) {
144- rc , isArchive , err := DetectArchiveReader (rc )
144+ rc , ok , err := DetectArchiveReader (rc )
145145 if err != nil {
146146 return nil , "" , err
147147 }
148148
149- if isArchive {
149+ if ok {
150150 return rc , dockerfileName , nil
151151 }
152152
@@ -171,14 +171,22 @@ func GetContextFromReader(rc io.ReadCloser, dockerfileName string) (out io.ReadC
171171
172172 return newReadCloserWrapper (tarArchive , func () error {
173173 err := tarArchive .Close ()
174- os .RemoveAll (dockerfileDir )
174+ _ = os .RemoveAll (dockerfileDir )
175175 return err
176176 }), DefaultDockerfileName , nil
177177}
178178
179179// IsArchive checks for the magic bytes of a tar or any supported compression
180180// algorithm.
181+ //
182+ // Deprecated: this utility was used internally and will be removed in the next release.
181183func IsArchive (header []byte ) bool {
184+ return isArchive (header )
185+ }
186+
187+ // isArchive checks for the magic bytes of a tar or any supported compression
188+ // algorithm.
189+ func isArchive (header []byte ) bool {
182190 if compression .Detect (header ) != compression .None {
183191 return true
184192 }
@@ -242,7 +250,7 @@ func getWithStatusError(url string) (resp *http.Response, err error) {
242250 }
243251 msg := fmt .Sprintf ("failed to GET %s with status %s" , url , resp .Status )
244252 body , err := io .ReadAll (resp .Body )
245- resp .Body .Close ()
253+ _ = resp .Body .Close ()
246254 if err != nil {
247255 return nil , errors .Wrapf (err , "%s: error reading body" , msg )
248256 }
@@ -374,7 +382,7 @@ func isUNC(path string) bool {
374382// the relative path to the dockerfile in the context.
375383func AddDockerfileToBuildContext (dockerfileCtx io.ReadCloser , buildCtx io.ReadCloser ) (io.ReadCloser , string , error ) {
376384 file , err := io .ReadAll (dockerfileCtx )
377- dockerfileCtx .Close ()
385+ _ = dockerfileCtx .Close ()
378386 if err != nil {
379387 return nil , "" , err
380388 }
@@ -438,17 +446,19 @@ func Compress(buildCtx io.ReadCloser) (io.ReadCloser, error) {
438446 go func () {
439447 compressWriter , err := compression .CompressStream (pipeWriter , archive .Gzip )
440448 if err != nil {
441- pipeWriter .CloseWithError (err )
449+ _ = pipeWriter .CloseWithError (err )
442450 }
443- defer buildCtx .Close ()
451+ defer func () {
452+ _ = buildCtx .Close ()
453+ }()
444454
445455 if _ , err := io .Copy (compressWriter , buildCtx ); err != nil {
446- pipeWriter .CloseWithError (errors .Wrap (err , "failed to compress context" ))
447- compressWriter .Close ()
456+ _ = pipeWriter .CloseWithError (errors .Wrap (err , "failed to compress context" ))
457+ _ = compressWriter .Close ()
448458 return
449459 }
450- compressWriter .Close ()
451- pipeWriter .Close ()
460+ _ = compressWriter .Close ()
461+ _ = pipeWriter .Close ()
452462 }()
453463
454464 return pipeReader , nil
0 commit comments