Skip to content

Commit b677cf9

Browse files
authored
Merge pull request #49072 from dmcgowan/decouple-archive-system
Decouple pkg/archive from pkg/system
2 parents 1a127ed + 315891d commit b677cf9

51 files changed

Lines changed: 270 additions & 505 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pkg/archive/archive.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Package archive provides helper functions for dealing with archive files.
2-
package archive // import "github.com/docker/docker/pkg/archive"
2+
package archive
33

44
import (
55
"archive/tar"
@@ -26,7 +26,6 @@ import (
2626
"github.com/containerd/log"
2727
"github.com/docker/docker/pkg/idtools"
2828
"github.com/docker/docker/pkg/pools"
29-
"github.com/docker/docker/pkg/system"
3029
"github.com/klauspost/compress/zstd"
3130
"github.com/moby/patternmatcher"
3231
"github.com/moby/sys/sequential"
@@ -507,7 +506,7 @@ func ReadSecurityXattrToTarHeader(path string, hdr *tar.Header) error {
507506
vfsCapRevision2 = 2
508507
vfsCapRevision3 = 3
509508
)
510-
capability, _ := system.Lgetxattr(path, "security.capability")
509+
capability, _ := lgetxattr(path, "security.capability")
511510
if capability != nil {
512511
if capability[versionOffset] == vfsCapRevision3 {
513512
// Convert VFS_CAP_REVISION_3 to VFS_CAP_REVISION_2 as root UID makes no
@@ -799,7 +798,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, o
799798
if !ok {
800799
continue
801800
}
802-
if err := system.Lsetxattr(path, xattr, []byte(value), 0); err != nil {
801+
if err := lsetxattr(path, xattr, []byte(value), 0); err != nil {
803802
if bestEffortXattrs && errors.Is(err, syscall.ENOTSUP) || errors.Is(err, syscall.EPERM) {
804803
// EPERM occurs if modifying xattrs is not allowed. This can
805804
// happen when running in userns with restrictions (ChromeOS).
@@ -822,26 +821,22 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, o
822821
return err
823822
}
824823

825-
aTime := hdr.AccessTime
826-
if aTime.Before(hdr.ModTime) {
827-
// Last access time should never be before last modified time.
828-
aTime = hdr.ModTime
829-
}
824+
aTime := boundTime(latestTime(hdr.AccessTime, hdr.ModTime))
825+
mTime := boundTime(hdr.ModTime)
830826

831-
// system.Chtimes doesn't support a NOFOLLOW flag atm
827+
// chtimes doesn't support a NOFOLLOW flag atm
832828
if hdr.Typeflag == tar.TypeLink {
833829
if fi, err := os.Lstat(hdr.Linkname); err == nil && (fi.Mode()&os.ModeSymlink == 0) {
834-
if err := system.Chtimes(path, aTime, hdr.ModTime); err != nil {
830+
if err := chtimes(path, aTime, mTime); err != nil {
835831
return err
836832
}
837833
}
838834
} else if hdr.Typeflag != tar.TypeSymlink {
839-
if err := system.Chtimes(path, aTime, hdr.ModTime); err != nil {
835+
if err := chtimes(path, aTime, mTime); err != nil {
840836
return err
841837
}
842838
} else {
843-
ts := []syscall.Timespec{timeToTimespec(aTime), timeToTimespec(hdr.ModTime)}
844-
if err := system.LUtimesNano(path, ts); err != nil && err != system.ErrNotSupportedPlatform {
839+
if err := lchtimes(path, aTime, mTime); err != nil {
845840
return err
846841
}
847842
}
@@ -1201,7 +1196,7 @@ loop:
12011196
// #nosec G305 -- The header was checked for path traversal before it was appended to the dirs slice.
12021197
path := filepath.Join(dest, hdr.Name)
12031198

1204-
if err := system.Chtimes(path, hdr.AccessTime, hdr.ModTime); err != nil {
1199+
if err := chtimes(path, boundTime(latestTime(hdr.AccessTime, hdr.ModTime)), boundTime(hdr.ModTime)); err != nil {
12051200
return err
12061201
}
12071202
}
@@ -1350,7 +1345,7 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
13501345
dst = filepath.Join(dst, filepath.Base(src))
13511346
}
13521347
// Create the holding directory if necessary
1353-
if err := system.MkdirAll(filepath.Dir(dst), 0o700); err != nil {
1348+
if err := os.MkdirAll(filepath.Dir(dst), 0o700); err != nil {
13541349
return err
13551350
}
13561351

pkg/archive/archive_linux.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package archive // import "github.com/docker/docker/pkg/archive"
1+
package archive
22

33
import (
44
"archive/tar"
@@ -7,7 +7,6 @@ import (
77
"path/filepath"
88
"strings"
99

10-
"github.com/docker/docker/pkg/system"
1110
"github.com/moby/sys/userns"
1211
"golang.org/x/sys/unix"
1312
)
@@ -39,7 +38,7 @@ func (overlayWhiteoutConverter) ConvertWrite(hdr *tar.Header, path string, fi os
3938
}
4039

4140
// convert opaque dirs to AUFS format by writing an empty file with the prefix
42-
opaque, err := system.Lgetxattr(path, opaqueXattrName)
41+
opaque, err := lgetxattr(path, opaqueXattrName)
4342
if err != nil {
4443
return nil, err
4544
}

pkg/archive/archive_linux_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package archive // import "github.com/docker/docker/pkg/archive"
1+
package archive
22

33
import (
44
"archive/tar"
@@ -9,7 +9,6 @@ import (
99
"syscall"
1010
"testing"
1111

12-
"github.com/docker/docker/pkg/system"
1312
"github.com/google/go-cmp/cmp/cmpopts"
1413
"github.com/moby/sys/userns"
1514
"golang.org/x/sys/unix"
@@ -35,7 +34,7 @@ func setupOverlayTestDir(t *testing.T, src string) {
3534
err := os.Mkdir(filepath.Join(src, "d1"), 0o700)
3635
assert.NilError(t, err)
3736

38-
err = system.Lsetxattr(filepath.Join(src, "d1"), "trusted.overlay.opaque", []byte("y"), 0)
37+
err = unix.Lsetxattr(filepath.Join(src, "d1"), "trusted.overlay.opaque", []byte("y"), 0)
3938
assert.NilError(t, err)
4039

4140
err = os.WriteFile(filepath.Join(src, "d1", "f1"), []byte{}, 0o600)
@@ -45,7 +44,7 @@ func setupOverlayTestDir(t *testing.T, src string) {
4544
err = os.Mkdir(filepath.Join(src, "d2"), 0o750)
4645
assert.NilError(t, err)
4746

48-
err = system.Lsetxattr(filepath.Join(src, "d2"), "trusted.overlay.opaque", []byte("y"), 0)
47+
err = unix.Lsetxattr(filepath.Join(src, "d2"), "trusted.overlay.opaque", []byte("y"), 0)
4948
assert.NilError(t, err)
5049

5150
err = os.WriteFile(filepath.Join(src, "d2", "f1"), []byte{}, 0o660)
@@ -55,12 +54,12 @@ func setupOverlayTestDir(t *testing.T, src string) {
5554
err = os.Mkdir(filepath.Join(src, "d3"), 0o700)
5655
assert.NilError(t, err)
5756

58-
err = system.Mknod(filepath.Join(src, "d3", "f1"), unix.S_IFCHR, 0)
57+
err = unix.Mknod(filepath.Join(src, "d3", "f1"), unix.S_IFCHR, 0)
5958
assert.NilError(t, err)
6059
}
6160

6261
func checkOpaqueness(t *testing.T, path string, opaque string) {
63-
xattrOpaque, err := system.Lgetxattr(path, "trusted.overlay.opaque")
62+
xattrOpaque, err := lgetxattr(path, "trusted.overlay.opaque")
6463
assert.NilError(t, err)
6564

6665
if string(xattrOpaque) != opaque {

pkg/archive/archive_other.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//go:build !linux
22

3-
package archive // import "github.com/docker/docker/pkg/archive"
3+
package archive
44

55
func getWhiteoutConverter(format WhiteoutFormat) tarWhiteoutConverter {
66
return nil

pkg/archive/archive_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package archive // import "github.com/docker/docker/pkg/archive"
1+
package archive
22

33
import (
44
"archive/tar"

pkg/archive/archive_unix.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//go:build !windows
22

3-
package archive // import "github.com/docker/docker/pkg/archive"
3+
package archive
44

55
import (
66
"archive/tar"
@@ -12,7 +12,6 @@ import (
1212
"syscall"
1313

1414
"github.com/docker/docker/pkg/idtools"
15-
"github.com/docker/docker/pkg/system"
1615
"golang.org/x/sys/unix"
1716
)
1817

@@ -109,7 +108,7 @@ func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error {
109108
mode |= unix.S_IFIFO
110109
}
111110

112-
return system.Mknod(path, mode, int(system.Mkdev(hdr.Devmajor, hdr.Devminor)))
111+
return mknod(path, mode, unix.Mkdev(uint32(hdr.Devmajor), uint32(hdr.Devminor)))
113112
}
114113

115114
func handleLChmod(hdr *tar.Header, path string, hdrInfo os.FileInfo) error {

pkg/archive/archive_unix_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//go:build !windows
22

3-
package archive // import "github.com/docker/docker/pkg/archive"
3+
package archive
44

55
import (
66
"archive/tar"
@@ -14,7 +14,6 @@ import (
1414
"syscall"
1515
"testing"
1616

17-
"github.com/docker/docker/pkg/system"
1817
"github.com/moby/sys/userns"
1918
"golang.org/x/sys/unix"
2019
"gotest.tools/v3/assert"
@@ -199,11 +198,11 @@ func TestTarWithBlockCharFifo(t *testing.T) {
199198
err = os.WriteFile(filepath.Join(origin, "1"), []byte("hello world"), 0o700)
200199
assert.NilError(t, err)
201200

202-
err = system.Mknod(filepath.Join(origin, "2"), unix.S_IFBLK, int(system.Mkdev(int64(12), int64(5))))
201+
err = mknod(filepath.Join(origin, "2"), unix.S_IFBLK, unix.Mkdev(uint32(12), uint32(5)))
203202
assert.NilError(t, err)
204-
err = system.Mknod(filepath.Join(origin, "3"), unix.S_IFCHR, int(system.Mkdev(int64(12), int64(5))))
203+
err = mknod(filepath.Join(origin, "3"), unix.S_IFCHR, unix.Mkdev(uint32(12), uint32(5)))
205204
assert.NilError(t, err)
206-
err = system.Mknod(filepath.Join(origin, "4"), unix.S_IFIFO, int(system.Mkdev(int64(12), int64(5))))
205+
err = mknod(filepath.Join(origin, "4"), unix.S_IFIFO, unix.Mkdev(uint32(12), uint32(5)))
207206
assert.NilError(t, err)
208207

209208
dest, err := os.MkdirTemp("", "docker-test-tar-hardlink-dest")

pkg/archive/archive_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package archive // import "github.com/docker/docker/pkg/archive"
1+
package archive
22

33
import (
44
"archive/tar"

pkg/archive/archive_windows_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//go:build windows
22

3-
package archive // import "github.com/docker/docker/pkg/archive"
3+
package archive
44

55
import (
66
"os"

pkg/archive/changes.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
package archive // import "github.com/docker/docker/pkg/archive"
1+
package archive
22

33
import (
44
"archive/tar"
55
"bytes"
66
"context"
77
"fmt"
88
"io"
9+
"io/fs"
910
"os"
1011
"path/filepath"
1112
"sort"
1213
"strings"
13-
"syscall"
1414
"time"
1515

1616
"github.com/containerd/log"
1717
"github.com/docker/docker/pkg/idtools"
1818
"github.com/docker/docker/pkg/pools"
19-
"github.com/docker/docker/pkg/system"
2019
)
2120

2221
// ChangeType represents the change type.
@@ -74,11 +73,6 @@ func sameFsTime(a, b time.Time) bool {
7473
(a.Nanosecond() == 0 || b.Nanosecond() == 0))
7574
}
7675

77-
func sameFsTimeSpec(a, b syscall.Timespec) bool {
78-
return a.Sec == b.Sec &&
79-
(a.Nsec == b.Nsec || a.Nsec == 0 || b.Nsec == 0)
80-
}
81-
8276
// Changes walks the path rw and determines changes for the files in the path,
8377
// with respect to the parent layers
8478
func Changes(layers []string, rw string) ([]Change, error) {
@@ -210,7 +204,7 @@ func changes(layers []string, rw string, dc deleteChange, sc skipChange) ([]Chan
210204
type FileInfo struct {
211205
parent *FileInfo
212206
name string
213-
stat *system.StatT
207+
stat fs.FileInfo
214208
children map[string]*FileInfo
215209
capability []byte
216210
added bool

0 commit comments

Comments
 (0)