diff --git a/Dockerfile b/Dockerfile index ecbc385d83..c3006e5025 100644 --- a/Dockerfile +++ b/Dockerfile @@ -288,7 +288,8 @@ RUN --mount=type=cache,sharing=locked,id=moby-dev-aptlib,target=/var/lib/apt \ vim-common \ xfsprogs \ xz-utils \ - zip + zip \ + zstd # Switch to use iptables instead of nftables (to match the CI hosts) diff --git a/pkg/archive/archive.go b/pkg/archive/archive.go index 65b341a99c..43890e4f8d 100644 --- a/pkg/archive/archive.go +++ b/pkg/archive/archive.go @@ -9,7 +9,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "path/filepath" "runtime" @@ -23,6 +22,7 @@ import ( "github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/pools" "github.com/docker/docker/pkg/system" + "github.com/klauspost/compress/zstd" "github.com/sirupsen/logrus" exec "golang.org/x/sys/execabs" ) @@ -84,6 +84,8 @@ const ( Gzip // Xz is xz compression algorithm. Xz + // Zstd is zstd compression algorithm. + Zstd ) const ( @@ -128,12 +130,9 @@ func DetectCompression(source []byte) Compression { Bzip2: {0x42, 0x5A, 0x68}, Gzip: {0x1F, 0x8B, 0x08}, Xz: {0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00}, + Zstd: {0x28, 0xb5, 0x2f, 0xfd}, } { - if len(source) < len(m) { - logrus.Debug("Len too short") - continue - } - if bytes.Equal(m, source[:len(m)]) { + if bytes.HasPrefix(source, m) { return compression } } @@ -147,20 +146,15 @@ func xzDecompress(ctx context.Context, archive io.Reader) (io.ReadCloser, error) } func gzDecompress(ctx context.Context, buf io.Reader) (io.ReadCloser, error) { - noPigzEnv := os.Getenv("MOBY_DISABLE_PIGZ") - var noPigz bool - - if noPigzEnv != "" { - var err error - noPigz, err = strconv.ParseBool(noPigzEnv) + if noPigzEnv := os.Getenv("MOBY_DISABLE_PIGZ"); noPigzEnv != "" { + noPigz, err := strconv.ParseBool(noPigzEnv) if err != nil { logrus.WithError(err).Warn("invalid value in MOBY_DISABLE_PIGZ env var") } - } - - if noPigz { - logrus.Debugf("Use of pigz is disabled due to MOBY_DISABLE_PIGZ=%s", noPigzEnv) - return gzip.NewReader(buf) + if noPigz { + logrus.Debugf("Use of pigz is disabled due to MOBY_DISABLE_PIGZ=%s", noPigzEnv) + return gzip.NewReader(buf) + } } unpigzPath, err := exec.LookPath("unpigz") @@ -225,6 +219,13 @@ func DecompressStream(archive io.Reader) (io.ReadCloser, error) { } readBufWrapper := p.NewReadCloserWrapper(buf, xzReader) return wrapReadCloser(readBufWrapper, cancel), nil + case Zstd: + zstdReader, err := zstd.NewReader(buf) + if err != nil { + return nil, err + } + readBufWrapper := p.NewReadCloserWrapper(buf, zstdReader) + return readBufWrapper, nil default: return nil, fmt.Errorf("Unsupported compression format %s", (&compression).Extension()) } @@ -278,7 +279,9 @@ func ReplaceFileTarWrapper(inputTarStream io.ReadCloser, mods map[string]TarModi return nil } - header.Name = name + if header.Name == "" { + header.Name = name + } header.Size = int64(len(data)) if err := tarWriter.WriteHeader(header); err != nil { return err @@ -349,6 +352,8 @@ func (compression *Compression) Extension() string { return "tar.gz" case Xz: return "tar.xz" + case Zstd: + return "tar.zst" } return "" } @@ -608,15 +613,11 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L if err != nil { return err } - - efw := ioutils.NewEagerFileWriter(file) - - if _, err := io.Copy(efw, reader); err != nil { + if _, err := io.Copy(file, reader); err != nil { file.Close() return err } - - efw.Close() + file.Close() case tar.TypeBlock, tar.TypeChar: if inUserns { // cannot create devices in a userns @@ -728,7 +729,6 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L return err } } - return nil } @@ -820,6 +820,11 @@ func TarWithOptions(srcPath string, options *TarOptions) (io.ReadCloser, error) for _, include := range options.IncludeFiles { rebaseName := options.RebaseNames[include] + var ( + parentMatched []bool + parentDirs []string + ) + walkRoot := getWalkRoot(srcPath, include) filepath.Walk(walkRoot, func(filePath string, f os.FileInfo, err error) error { if err != nil { @@ -846,11 +851,29 @@ func TarWithOptions(srcPath string, options *TarOptions) (io.ReadCloser, error) // is asking for that file no matter what - which is true // for some files, like .dockerignore and Dockerfile (sometimes) if include != relFilePath { - skip, err = pm.Matches(relFilePath) + for len(parentDirs) != 0 { + lastParentDir := parentDirs[len(parentDirs)-1] + if strings.HasPrefix(relFilePath, lastParentDir+string(os.PathSeparator)) { + break + } + parentDirs = parentDirs[:len(parentDirs)-1] + parentMatched = parentMatched[:len(parentMatched)-1] + } + + if len(parentMatched) != 0 { + skip, err = pm.Matches(relFilePath) + } else { + skip, err = pm.Matches(relFilePath) + } if err != nil { logrus.Errorf("Error matching %s: %v", relFilePath, err) return err } + + if f.IsDir() { + parentDirs = append(parentDirs, relFilePath) + parentMatched = append(parentMatched, skip) + } } if skip { @@ -1094,7 +1117,6 @@ func untarHandler(tarArchive io.Reader, dest string, options *TarOptions, decomp // TarUntar is a convenience function which calls Tar and Untar, with the output of one piped into the other. // If either Tar or Untar fails, TarUntar aborts and returns the error. func (archiver *Archiver) TarUntar(src, dst string) error { - logrus.Debugf("TarUntar(%s %s)", src, dst) archive, err := TarWithOptions(src, &TarOptions{Compression: Uncompressed}) if err != nil { return err @@ -1139,11 +1161,9 @@ func (archiver *Archiver) CopyWithTar(src, dst string) error { // as owner rootIDs := archiver.IDMapping.RootPair() // Create dst, copy src's content into it - logrus.Debugf("Creating dest directory: %s", dst) if err := idtools.MkdirAllAndChownNew(dst, 0755, rootIDs); err != nil { return err } - logrus.Debugf("Calling TarUntar(%s, %s)", src, dst) return archiver.TarUntar(src, dst) } @@ -1151,7 +1171,6 @@ func (archiver *Archiver) CopyWithTar(src, dst string) error { // for a single file. It copies a regular file from path `src` to // path `dst`, and preserves all its metadata. func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) { - logrus.Debugf("CopyFileWithTar(%s, %s)", src, dst) srcSt, err := os.Stat(src) if err != nil { return err @@ -1277,7 +1296,7 @@ func cmdStream(cmd *exec.Cmd, input io.Reader) (io.ReadCloser, error) { // of that file as an archive. The archive can only be read once - as soon as reading completes, // the file will be deleted. func NewTempArchive(src io.Reader, dir string) (*TempArchive, error) { - f, err := ioutil.TempFile(dir, "") + f, err := os.CreateTemp(dir, "") if err != nil { return nil, err } @@ -1324,4 +1343,4 @@ func (archive *TempArchive) Read(data []byte) (int, error) { os.Remove(archive.File.Name()) } return n, err -} +} \ No newline at end of file diff --git a/pkg/archive/archive_test.go b/pkg/archive/archive_test.go index d7632e1f06..14f471a0d0 100644 --- a/pkg/archive/archive_test.go +++ b/pkg/archive/archive_test.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -17,7 +16,7 @@ import ( "testing" "time" - "github.com/containerd/containerd/sys" + "github.com/containerd/containerd/pkg/userns" "github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/ioutils" "gotest.tools/v3/assert" @@ -111,7 +110,7 @@ func testDecompressStream(t *testing.T, ext, compressCommand string) io.Reader { if err != nil { t.Fatalf("Failed to decompress %s: %v", filename, err) } - if _, err = ioutil.ReadAll(r); err != nil { + if _, err = io.ReadAll(r); err != nil { t.Fatalf("Failed to read the decompressed stream: %v ", err) } if err = r.Close(); err != nil { @@ -136,6 +135,13 @@ func TestDecompressStreamXz(t *testing.T) { testDecompressStream(t, "xz", "xz -f") } +func TestDecompressStreamZstd(t *testing.T) { + if _, err := exec.LookPath("zstd"); err != nil { + t.Skip("zstd not installed") + } + testDecompressStream(t, "zst", "zstd -f") +} + func TestCompressStreamXzUnsupported(t *testing.T) { dest, err := os.Create(tmp + "dest") if err != nil { @@ -211,6 +217,13 @@ func TestExtensionXz(t *testing.T) { t.Fatalf("The extension of a xz archive should be 'tar.xz'") } } +func TestExtensionZstd(t *testing.T) { + compression := Zstd + output := compression.Extension() + if output != "tar.zst" { + t.Fatalf("The extension of a zstd archive should be 'tar.zst'") + } +} func TestCmdStreamLargeStderr(t *testing.T) { cmd := exec.Command("sh", "-c", "dd if=/dev/zero bs=1k count=1000 of=/dev/stderr; echo hello") @@ -220,7 +233,7 @@ func TestCmdStreamLargeStderr(t *testing.T) { } errCh := make(chan error, 1) go func() { - _, err := io.Copy(ioutil.Discard, out) + _, err := io.Copy(io.Discard, out) errCh <- err }() select { @@ -243,7 +256,7 @@ func TestCmdStreamBad(t *testing.T) { if err != nil { t.Fatalf("Failed to start command: %s", err) } - if output, err := ioutil.ReadAll(out); err == nil { + if output, err := io.ReadAll(out); err == nil { t.Fatalf("Command should have failed") } else if err.Error() != "exit status 1: error couldn't reverse the phase pulser\n" { t.Fatalf("Wrong error value (%s)", err) @@ -258,7 +271,7 @@ func TestCmdStreamGood(t *testing.T) { if err != nil { t.Fatal(err) } - if output, err := ioutil.ReadAll(out); err != nil { + if output, err := io.ReadAll(out); err != nil { t.Fatalf("Command should not have failed (err=%s)", err) } else if s := string(output); s != "hello\n" { t.Fatalf("Command output should be '%s', not '%s'", "hello\\n", output) @@ -266,7 +279,7 @@ func TestCmdStreamGood(t *testing.T) { } func TestUntarPathWithInvalidDest(t *testing.T) { - tempFolder, err := ioutil.TempDir("", "docker-archive-test") + tempFolder, err := os.MkdirTemp("", "docker-archive-test") assert.NilError(t, err) defer os.RemoveAll(tempFolder) invalidDestFolder := filepath.Join(tempFolder, "invalidDest") @@ -295,7 +308,7 @@ func TestUntarPathWithInvalidDest(t *testing.T) { } func TestUntarPathWithInvalidSrc(t *testing.T) { - dest, err := ioutil.TempDir("", "docker-archive-test") + dest, err := os.MkdirTemp("", "docker-archive-test") if err != nil { t.Fatalf("Fail to create the destination file") } @@ -308,7 +321,7 @@ func TestUntarPathWithInvalidSrc(t *testing.T) { func TestUntarPath(t *testing.T) { skip.If(t, runtime.GOOS != "windows" && os.Getuid() != 0, "skipping test that requires root") - tmpFolder, err := ioutil.TempDir("", "docker-archive-test") + tmpFolder, err := os.MkdirTemp("", "docker-archive-test") assert.NilError(t, err) defer os.RemoveAll(tmpFolder) srcFile := filepath.Join(tmpFolder, "src") @@ -345,7 +358,7 @@ func TestUntarPath(t *testing.T) { // Do the same test as above but with the destination as file, it should fail func TestUntarPathWithDestinationFile(t *testing.T) { - tmpFolder, err := ioutil.TempDir("", "docker-archive-test") + tmpFolder, err := os.MkdirTemp("", "docker-archive-test") if err != nil { t.Fatal(err) } @@ -381,7 +394,7 @@ func TestUntarPathWithDestinationFile(t *testing.T) { // and the destination file is a directory // It's working, see https://github.com/docker/docker/issues/10040 func TestUntarPathWithDestinationSrcFileAsFolder(t *testing.T) { - tmpFolder, err := ioutil.TempDir("", "docker-archive-test") + tmpFolder, err := os.MkdirTemp("", "docker-archive-test") if err != nil { t.Fatal(err) } @@ -421,7 +434,7 @@ func TestUntarPathWithDestinationSrcFileAsFolder(t *testing.T) { } func TestCopyWithTarInvalidSrc(t *testing.T) { - tempFolder, err := ioutil.TempDir("", "docker-archive-test") + tempFolder, err := os.MkdirTemp("", "docker-archive-test") if err != nil { t.Fatal(nil) } @@ -439,7 +452,7 @@ func TestCopyWithTarInvalidSrc(t *testing.T) { func TestCopyWithTarInexistentDestWillCreateIt(t *testing.T) { skip.If(t, runtime.GOOS != "windows" && os.Getuid() != 0, "skipping test that requires root") - tempFolder, err := ioutil.TempDir("", "docker-archive-test") + tempFolder, err := os.MkdirTemp("", "docker-archive-test") if err != nil { t.Fatal(nil) } @@ -461,7 +474,7 @@ func TestCopyWithTarInexistentDestWillCreateIt(t *testing.T) { // Test CopyWithTar with a file as src func TestCopyWithTarSrcFile(t *testing.T) { - folder, err := ioutil.TempDir("", "docker-archive-test") + folder, err := os.MkdirTemp("", "docker-archive-test") if err != nil { t.Fatal(err) } @@ -477,7 +490,7 @@ func TestCopyWithTarSrcFile(t *testing.T) { if err != nil { t.Fatal(err) } - ioutil.WriteFile(src, []byte("content"), 0777) + os.WriteFile(src, []byte("content"), 0777) err = defaultCopyWithTar(src, dest) if err != nil { t.Fatalf("archiver.CopyWithTar shouldn't throw an error, %s.", err) @@ -491,7 +504,7 @@ func TestCopyWithTarSrcFile(t *testing.T) { // Test CopyWithTar with a folder as src func TestCopyWithTarSrcFolder(t *testing.T) { - folder, err := ioutil.TempDir("", "docker-archive-test") + folder, err := os.MkdirTemp("", "docker-archive-test") if err != nil { t.Fatal(err) } @@ -506,7 +519,7 @@ func TestCopyWithTarSrcFolder(t *testing.T) { if err != nil { t.Fatal(err) } - ioutil.WriteFile(filepath.Join(src, "file"), []byte("content"), 0777) + os.WriteFile(filepath.Join(src, "file"), []byte("content"), 0777) err = defaultCopyWithTar(src, dest) if err != nil { t.Fatalf("archiver.CopyWithTar shouldn't throw an error, %s.", err) @@ -519,7 +532,7 @@ func TestCopyWithTarSrcFolder(t *testing.T) { } func TestCopyFileWithTarInvalidSrc(t *testing.T) { - tempFolder, err := ioutil.TempDir("", "docker-archive-test") + tempFolder, err := os.MkdirTemp("", "docker-archive-test") if err != nil { t.Fatal(err) } @@ -537,7 +550,7 @@ func TestCopyFileWithTarInvalidSrc(t *testing.T) { } func TestCopyFileWithTarInexistentDestWillCreateIt(t *testing.T) { - tempFolder, err := ioutil.TempDir("", "docker-archive-test") + tempFolder, err := os.MkdirTemp("", "docker-archive-test") if err != nil { t.Fatal(nil) } @@ -560,7 +573,7 @@ func TestCopyFileWithTarInexistentDestWillCreateIt(t *testing.T) { } func TestCopyFileWithTarSrcFolder(t *testing.T) { - folder, err := ioutil.TempDir("", "docker-archive-copyfilewithtar-test") + folder, err := os.MkdirTemp("", "docker-archive-copyfilewithtar-test") if err != nil { t.Fatal(err) } @@ -582,7 +595,7 @@ func TestCopyFileWithTarSrcFolder(t *testing.T) { } func TestCopyFileWithTarSrcFile(t *testing.T) { - folder, err := ioutil.TempDir("", "docker-archive-test") + folder, err := os.MkdirTemp("", "docker-archive-test") if err != nil { t.Fatal(err) } @@ -598,7 +611,7 @@ func TestCopyFileWithTarSrcFile(t *testing.T) { if err != nil { t.Fatal(err) } - ioutil.WriteFile(src, []byte("content"), 0777) + os.WriteFile(src, []byte("content"), 0777) err = defaultCopyWithTar(src, dest+"/") if err != nil { t.Fatalf("archiver.CopyFileWithTar shouldn't throw an error, %s.", err) @@ -621,13 +634,13 @@ func TestTarFiles(t *testing.T) { } func checkNoChanges(fileNum int, hardlinks bool) error { - srcDir, err := ioutil.TempDir("", "docker-test-srcDir") + srcDir, err := os.MkdirTemp("", "docker-test-srcDir") if err != nil { return err } defer os.RemoveAll(srcDir) - destDir, err := ioutil.TempDir("", "docker-test-destDir") + destDir, err := os.MkdirTemp("", "docker-test-destDir") if err != nil { return err } @@ -672,7 +685,7 @@ func tarUntar(t *testing.T, origin string, options *TarOptions) ([]Change, error return nil, fmt.Errorf("Wrong compression detected. Actual compression: %s, found %s", compression.Extension(), detectedCompression.Extension()) } - tmp, err := ioutil.TempDir("", "docker-test-untar") + tmp, err := os.MkdirTemp("", "docker-test-untar") if err != nil { return nil, err } @@ -688,18 +701,18 @@ func tarUntar(t *testing.T, origin string, options *TarOptions) ([]Change, error } func TestTarUntar(t *testing.T) { - origin, err := ioutil.TempDir("", "docker-test-untar-origin") + origin, err := os.MkdirTemp("", "docker-test-untar-origin") if err != nil { t.Fatal(err) } defer os.RemoveAll(origin) - if err := ioutil.WriteFile(filepath.Join(origin, "1"), []byte("hello world"), 0700); err != nil { + if err := os.WriteFile(filepath.Join(origin, "1"), []byte("hello world"), 0700); err != nil { t.Fatal(err) } - if err := ioutil.WriteFile(filepath.Join(origin, "2"), []byte("welcome!"), 0700); err != nil { + if err := os.WriteFile(filepath.Join(origin, "2"), []byte("welcome!"), 0700); err != nil { t.Fatal(err) } - if err := ioutil.WriteFile(filepath.Join(origin, "3"), []byte("will be ignored"), 0700); err != nil { + if err := os.WriteFile(filepath.Join(origin, "3"), []byte("will be ignored"), 0700); err != nil { t.Fatal(err) } @@ -723,12 +736,12 @@ func TestTarUntar(t *testing.T) { } func TestTarWithOptionsChownOptsAlwaysOverridesIdPair(t *testing.T) { - origin, err := ioutil.TempDir("", "docker-test-tar-chown-opt") + origin, err := os.MkdirTemp("", "docker-test-tar-chown-opt") assert.NilError(t, err) defer os.RemoveAll(origin) filePath := filepath.Join(origin, "1") - err = ioutil.WriteFile(filePath, []byte("hello world"), 0700) + err = os.WriteFile(filePath, []byte("hello world"), 0700) assert.NilError(t, err) idMaps := []idtools.IDMap{ @@ -774,18 +787,18 @@ func TestTarWithOptionsChownOptsAlwaysOverridesIdPair(t *testing.T) { } func TestTarWithOptions(t *testing.T) { - origin, err := ioutil.TempDir("", "docker-test-untar-origin") + origin, err := os.MkdirTemp("", "docker-test-untar-origin") if err != nil { t.Fatal(err) } - if _, err := ioutil.TempDir(origin, "folder"); err != nil { + if _, err := os.MkdirTemp(origin, "folder"); err != nil { t.Fatal(err) } defer os.RemoveAll(origin) - if err := ioutil.WriteFile(filepath.Join(origin, "1"), []byte("hello world"), 0700); err != nil { + if err := os.WriteFile(filepath.Join(origin, "1"), []byte("hello world"), 0700); err != nil { t.Fatal(err) } - if err := ioutil.WriteFile(filepath.Join(origin, "2"), []byte("welcome!"), 0700); err != nil { + if err := os.WriteFile(filepath.Join(origin, "2"), []byte("welcome!"), 0700); err != nil { t.Fatal(err) } @@ -816,7 +829,7 @@ func TestTarWithOptions(t *testing.T) { // Failing prevents the archives from being uncompressed during ADD func TestTypeXGlobalHeaderDoesNotFail(t *testing.T) { hdr := tar.Header{Typeflag: tar.TypeXGlobalHeader} - tmpDir, err := ioutil.TempDir("", "docker-test-archive-pax-test") + tmpDir, err := os.MkdirTemp("", "docker-test-archive-pax-test") if err != nil { t.Fatal(err) } @@ -862,7 +875,7 @@ func prepareUntarSourceDirectory(numberOfFiles int, targetPath string, makeLinks fileData := []byte("fooo") for n := 0; n < numberOfFiles; n++ { fileName := fmt.Sprintf("file-%d", n) - if err := ioutil.WriteFile(filepath.Join(targetPath, fileName), fileData, 0700); err != nil { + if err := os.WriteFile(filepath.Join(targetPath, fileName), fileData, 0700); err != nil { return 0, err } if makeLinks { @@ -876,11 +889,11 @@ func prepareUntarSourceDirectory(numberOfFiles int, targetPath string, makeLinks } func BenchmarkTarUntar(b *testing.B) { - origin, err := ioutil.TempDir("", "docker-test-untar-origin") + origin, err := os.MkdirTemp("", "docker-test-untar-origin") if err != nil { b.Fatal(err) } - tempDir, err := ioutil.TempDir("", "docker-test-untar-destination") + tempDir, err := os.MkdirTemp("", "docker-test-untar-destination") if err != nil { b.Fatal(err) } @@ -904,11 +917,11 @@ func BenchmarkTarUntar(b *testing.B) { } func BenchmarkTarUntarWithLinks(b *testing.B) { - origin, err := ioutil.TempDir("", "docker-test-untar-origin") + origin, err := os.MkdirTemp("", "docker-test-untar-origin") if err != nil { b.Fatal(err) } - tempDir, err := ioutil.TempDir("", "docker-test-untar-destination") + tempDir, err := os.MkdirTemp("", "docker-test-untar-destination") if err != nil { b.Fatal(err) } @@ -1159,7 +1172,7 @@ func TestUntarInvalidSymlink(t *testing.T) { } func TestTempArchiveCloseMultipleTimes(t *testing.T) { - reader := ioutil.NopCloser(strings.NewReader("hello")) + reader := io.NopCloser(strings.NewReader("hello")) tempArchive, err := NewTempArchive(reader, "") assert.NilError(t, err) buf := make([]byte, 10) @@ -1184,7 +1197,7 @@ func TestXGlobalNoParent(t *testing.T) { Typeflag: tar.TypeXGlobalHeader, }) assert.NilError(t, err) - tmpDir, err := ioutil.TempDir("", "pax-test") + tmpDir, err := os.MkdirTemp("", "pax-test") assert.NilError(t, err) defer os.RemoveAll(tmpDir) err = Untar(buf, tmpDir, nil) @@ -1251,11 +1264,11 @@ func TestReplaceFileTarWrapper(t *testing.T) { // version of this package that was built with <=go17 are still readable. func TestPrefixHeaderReadable(t *testing.T) { skip.If(t, runtime.GOOS != "windows" && os.Getuid() != 0, "skipping test that requires root") - skip.If(t, sys.RunningInUserNS(), "skipping test that requires more than 010000000 UIDs, which is unlikely to be satisfied when running in userns") + skip.If(t, userns.RunningInUserNS(), "skipping test that requires more than 010000000 UIDs, which is unlikely to be satisfied when running in userns") // https://gist.github.com/stevvooe/e2a790ad4e97425896206c0816e1a882#file-out-go var testFile = []byte("\x1f\x8b\x08\x08\x44\x21\x68\x59\x00\x03\x74\x2e\x74\x61\x72\x00\x4b\xcb\xcf\x67\xa0\x35\x30\x80\x00\x86\x06\x10\x47\x01\xc1\x37\x40\x00\x54\xb6\xb1\xa1\xa9\x99\x09\x48\x25\x1d\x40\x69\x71\x49\x62\x91\x02\xe5\x76\xa1\x79\x84\x21\x91\xd6\x80\x72\xaf\x8f\x82\x51\x30\x0a\x46\x36\x00\x00\xf0\x1c\x1e\x95\x00\x06\x00\x00") - tmpDir, err := ioutil.TempDir("", "prefix-test") + tmpDir, err := os.MkdirTemp("", "prefix-test") assert.NilError(t, err) defer os.RemoveAll(tmpDir) err = Untar(bytes.NewReader(testFile), tmpDir, nil) @@ -1269,7 +1282,7 @@ func TestPrefixHeaderReadable(t *testing.T) { } func buildSourceArchive(t *testing.T, numberOfFiles int) (io.ReadCloser, func()) { - srcDir, err := ioutil.TempDir("", "docker-test-srcDir") + srcDir, err := os.MkdirTemp("", "docker-test-srcDir") assert.NilError(t, err) _, err = prepareUntarSourceDirectory(numberOfFiles, srcDir, false) @@ -1310,17 +1323,17 @@ func appendModifier(path string, header *tar.Header, content io.Reader) (*tar.He func readFileFromArchive(t *testing.T, archive io.ReadCloser, name string, expectedCount int, doc string) string { skip.If(t, runtime.GOOS != "windows" && os.Getuid() != 0, "skipping test that requires root") - destDir, err := ioutil.TempDir("", "docker-test-destDir") + destDir, err := os.MkdirTemp("", "docker-test-destDir") assert.NilError(t, err) defer os.RemoveAll(destDir) err = Untar(archive, destDir, nil) assert.NilError(t, err) - files, _ := ioutil.ReadDir(destDir) + files, _ := os.ReadDir(destDir) assert.Check(t, is.Len(files, expectedCount), doc) - content, err := ioutil.ReadFile(filepath.Join(destDir, name)) + content, err := os.ReadFile(filepath.Join(destDir, name)) assert.Check(t, err) return string(content) } @@ -1360,4 +1373,4 @@ func TestPigz(t *testing.T) { t.Log("Tested whether Pigz is not used, as it not installed") assert.Equal(t, reflect.TypeOf(contextReaderCloserWrapper.Reader), reflect.TypeOf(&gzip.Reader{})) } -} +} \ No newline at end of file