From c52fa073cd14498d060f0d8d99e9909737b729b5 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 13 Oct 2025 15:23:50 +0200 Subject: [PATCH] cli/command/image/build: deprecate DetectArchiveReader util It was only used internal in the package. Signed-off-by: Sebastiaan van Stijn --- cli/command/image/build/context.go | 13 ++++++++++++- cli/command/image/build/context_test.go | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cli/command/image/build/context.go b/cli/command/image/build/context.go index cfc4ec625..4c8bd2f8a 100644 --- a/cli/command/image/build/context.go +++ b/cli/command/image/build/context.go @@ -105,7 +105,18 @@ func filepathMatches(matcher *patternmatcher.PatternMatcher, file string) (bool, // of input. If an archive is detected, ok is set to true, and to false // otherwise, in which case it is safe to assume input represents the contents // of a Dockerfile. +// +// Deprecated: this utility was only used internally, and will be removed in the next release. func DetectArchiveReader(input io.ReadCloser) (rc io.ReadCloser, ok bool, err error) { + return detectArchiveReader(input) +} + +// detectArchiveReader detects whether the input stream is an archive or a +// Dockerfile and returns a buffered version of input, safe to consume in lieu +// of input. If an archive is detected, ok is set to true, and to false +// otherwise, in which case it is safe to assume input represents the contents +// of a Dockerfile. +func detectArchiveReader(input io.ReadCloser) (rc io.ReadCloser, ok bool, err error) { buf := bufio.NewReader(input) magic, err := buf.Peek(archiveHeaderSize * 2) @@ -146,7 +157,7 @@ func WriteTempDockerfile(rc io.ReadCloser) (dockerfileDir string, err error) { // Dockerfile or tar archive. Returns a tar archive used as a context and a // path to the Dockerfile inside the tar. func GetContextFromReader(rc io.ReadCloser, dockerfileName string) (out io.ReadCloser, relDockerfile string, err error) { - rc, ok, err := DetectArchiveReader(rc) + rc, ok, err := detectArchiveReader(rc) if err != nil { return nil, "", err } diff --git a/cli/command/image/build/context_test.go b/cli/command/image/build/context_test.go index 05f4798ac..b0c83a46b 100644 --- a/cli/command/image/build/context_test.go +++ b/cli/command/image/build/context_test.go @@ -326,7 +326,7 @@ func TestDetectArchiveReader(t *testing.T) { _ = content.Close() }() - _, isArchive, err := DetectArchiveReader(content) + _, isArchive, err := detectArchiveReader(content) assert.NilError(t, err) assert.Check(t, is.Equal(tc.expected, isArchive), tc.file) })