|
@@ -1,6 +1,9 @@
|
|
|
package archive // import "github.com/docker/docker/pkg/archive"
|
|
|
|
|
|
import (
|
|
|
+ "archive/tar"
|
|
|
+ "bytes"
|
|
|
+ "io"
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
"syscall"
|
|
@@ -8,8 +11,10 @@ import (
|
|
|
|
|
|
"github.com/containerd/containerd/pkg/userns"
|
|
|
"github.com/docker/docker/pkg/system"
|
|
|
+ "github.com/google/go-cmp/cmp/cmpopts"
|
|
|
"golang.org/x/sys/unix"
|
|
|
"gotest.tools/v3/assert"
|
|
|
+ is "gotest.tools/v3/assert/cmp"
|
|
|
"gotest.tools/v3/skip"
|
|
|
)
|
|
|
|
|
@@ -103,11 +108,39 @@ func TestOverlayTarUntar(t *testing.T) {
|
|
|
Compression: Uncompressed,
|
|
|
WhiteoutFormat: OverlayWhiteoutFormat,
|
|
|
}
|
|
|
- archive, err := TarWithOptions(src, options)
|
|
|
- assert.NilError(t, err)
|
|
|
- defer archive.Close()
|
|
|
+ reader, err := TarWithOptions(src, options)
|
|
|
+ assert.NilError(t, err)
|
|
|
+ archive, err := io.ReadAll(reader)
|
|
|
+ reader.Close()
|
|
|
+ assert.NilError(t, err)
|
|
|
+
|
|
|
+ // The archive should encode opaque directories and file whiteouts
|
|
|
+ // in AUFS format.
|
|
|
+ entries := make(map[string]struct{})
|
|
|
+ rdr := tar.NewReader(bytes.NewReader(archive))
|
|
|
+ for {
|
|
|
+ h, err := rdr.Next()
|
|
|
+ if err == io.EOF {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ assert.NilError(t, err)
|
|
|
+ assert.Check(t, is.Equal(h.Devmajor, int64(0)), "unexpected device file in archive")
|
|
|
+ assert.Check(t, is.DeepEqual(h.PAXRecords, map[string]string(nil), cmpopts.EquateEmpty()))
|
|
|
+ entries[h.Name] = struct{}{}
|
|
|
+ }
|
|
|
+
|
|
|
+ assert.DeepEqual(t, entries, map[string]struct{}{
|
|
|
+ "d1/": {},
|
|
|
+ "d1/" + WhiteoutOpaqueDir: {},
|
|
|
+ "d1/f1": {},
|
|
|
+ "d2/": {},
|
|
|
+ "d2/" + WhiteoutOpaqueDir: {},
|
|
|
+ "d2/f1": {},
|
|
|
+ "d3/": {},
|
|
|
+ "d3/" + WhiteoutPrefix + "f1": {},
|
|
|
+ })
|
|
|
|
|
|
- err = Untar(archive, dst, options)
|
|
|
+ err = Untar(bytes.NewReader(archive), dst, options)
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
checkFileMode(t, filepath.Join(dst, "d1"), 0o700|os.ModeDir)
|