Decouple pkg/archive from pkg/system#49072
Conversation
d0a8986 to
670cc2d
Compare
| } | ||
|
|
||
| if !system.IsAbs(linkTarget) { | ||
| if !filepath.IsAbs(linkTarget) { |
There was a problem hiding this comment.
Possibly we need to copy the system.IsAbs here for cross platform; see
Lines 9 to 19 in 7faa4ec
There was a problem hiding this comment.
☝️ looks like I wrote that up earlier today, but didn't submit. Per discussion in the call; we may not need this, or indeed can create a local copy of it.
There was a problem hiding this comment.
We shouldn't need it here since we are not running it on non-sanitized input
pkg/archive/path_unix.go
Outdated
| // lsetxattr sets the value of the extended attribute identified by attr | ||
| // and associated with the given path in the file system. | ||
| func lsetxattr(path string, attr string, data []byte, flags int) error { | ||
| return unix.Lsetxattr(path, attr, data, flags) | ||
| } |
There was a problem hiding this comment.
Looks like this implementation of set/get xattr didn't preserve the improvements that were made to provide more information about the name of the attribute that failed;
- Fail unpacking images with xattrs to filesystems without xattr support #45464
- pkg/system: return even richer xattr errors #47174
Should we preserve that?
There was a problem hiding this comment.
I'll put the path error back and just wrap the error there. Introducing a new error type is not needed and creates another dependency.
There was a problem hiding this comment.
Yeah, I don't think the error-type was matched anywhere, but it was purely for formatting (?)
670cc2d to
61d01b1
Compare
|
did a quick rebase after #49098 was merged |
eacfa48 to
efd6a9f
Compare
thaJeztah
left a comment
There was a problem hiding this comment.
Looks like this needs to add back some platform-specific implementations that were provided by pkg/system (see comments)
pkg/archive/archive_unix.go
Outdated
| return system.Mknod(path, mode, int(system.Mkdev(hdr.Devmajor, hdr.Devminor))) | ||
| return unix.Mknod(path, mode, int(unix.Mkdev(uint32(hdr.Devmajor), uint32(hdr.Devminor)))) |
There was a problem hiding this comment.
This needs differentiation, because the new implementation doesn't support (Free)BSD; moby/buildkit#5602
49.21 # github.com/docker/docker/pkg/archive
49.21 vendor/github.com/docker/docker/pkg/archive/archive_unix.go:111:32: cannot use int(unix.Mkdev(uint32(hdr.Devmajor), uint32(hdr.Devminor))) (value of type int) as uint64 value in argument to unix.Mknod
There was a problem hiding this comment.
pkg/archive/path_unix.go
Outdated
| if errors.Is(err, unix.ENODATA) { | ||
| return nil, nil | ||
| } |
There was a problem hiding this comment.
Here as well; looks like this doesn't support (Free)BSD; moby/buildkit#5602
49.21 vendor/github.com/docker/docker/pkg/archive/path_unix.go:38:26: undefined: unix.ENODATA
There was a problem hiding this comment.
Looks like FreeBSD has ENOATTR instead:
If the named attribute does not exist, or the process has no access to this attribute, errno is set to ENOATTR.
87 ENOATTR Attribute not found. The specified extended attribute does not exist.
pkg/archive/path_unix.go
Outdated
| // Buffer too small, use zero-sized buffer to get the actual size | ||
| sz, err = unix.Lgetxattr(path, attr, []byte{}) |
There was a problem hiding this comment.
More failures in the buildx repository, which also runs on OpenBSD (looks like xattrs are not supported there);
#25 [linux/amd64->openbsd/amd64 buildx-build 1/1] RUN --mount=type=bind,target=. --mount=type=cache,target=/root/.cache --mount=type=cache,target=/go/pkg/mod --mount=type=bind,from=buildx-version,source=/buildx-version,target=/buildx-version <<EOT (set -e...)
#25 0.070 + CGO_ENABLED=0 go build -mod vendor -trimpath -ldflags '-X github.com/docker/buildx/version.Version=53dca9a -X github.com/docker/buildx/version.Revision=53dca9a8946feca5ba7a63cb96140d94f2067656 -X github.com/docker/buildx/version.Package=github.com/docker/buildx -s -w' -o /usr/bin/docker-buildx ./cmd/buildx
#25 35.10 # github.com/docker/docker/pkg/archive
#25 35.10 vendor/github.com/docker/docker/pkg/archive/path_unix.go:25:18: undefined: unix.Lgetxattr
#25 35.10 vendor/github.com/docker/docker/pkg/archive/path_unix.go:29:18: undefined: unix.Lgetxattr
#25 35.10 vendor/github.com/docker/docker/pkg/archive/path_unix.go:34:18: undefined: unix.Lgetxattr
#25 35.10 vendor/github.com/docker/docker/pkg/archive/path_unix.go:38:26: undefined: unix.ENODATA
#25 35.10 vendor/github.com/docker/docker/pkg/archive/path_unix.go:50:53: undefined: unix.Lsetxattr
There was a problem hiding this comment.
Previously this code was in _linux.go file, so the xattrs were not used on BSD before. I think we can leave making the BSD work for a follow up.
There was a problem hiding this comment.
Updated, it should match what is defined in golang.org/x/sys/unix now
efd6a9f to
95a218f
Compare
|
Updated, @thaJeztah can you bump the golang sys package in that buildx PR |
thaJeztah
left a comment
There was a problem hiding this comment.
overall LGTM
Left one question (before blaming myself not asking), and some minor nits; no blockers AFAICS, just "touching up" in case you're doing another push.
pkg/archive/time.go
Outdated
| const maxSeconds = (1<<63 - 1) / int64(1e9) | ||
|
|
||
| func sanitizeTime(t time.Time) time.Time { | ||
| if ut := t.Unix(); ut < 0 || ut > maxSeconds { | ||
| return time.Unix(0, 0) | ||
| } | ||
| return t | ||
| } |
There was a problem hiding this comment.
Just to make sure I blame myself not asking; I recall there was some special handling for 32-bit; is that no longer needed, or was that only needed for Windows situations?
Lines 10 to 27 in bdfc384
There was a problem hiding this comment.
I'm just going to pull in containerd's implementation for this, at some point we should have this unified
|
|
||
| import "golang.org/x/sys/unix" | ||
|
|
||
| var mknod = unix.Mknod |
There was a problem hiding this comment.
More a "comment" than "need to change". I took this approach as well in some cases, but found that sometimes it became confusing, because this will be listed under variables in GoDoc, not under functions. Less relevant for non-exported functions, but for that reason I sometimes started to lean towards adding a wrapper function instead, i.e..
func mknod(path string, mode uint32, dev uint64)) error {
return unix.Mknod(path, mode, dev)
}(no need to change, fine as-is IMO)
Update archive time logic to mirror containerd's Signed-off-by: Derek McGowan <[email protected]>
Signed-off-by: Derek McGowan <[email protected]>
Signed-off-by: Derek McGowan <[email protected]>
Signed-off-by: Derek McGowan <[email protected]>
These were previously only used for pkg/archive Signed-off-by: Derek McGowan <[email protected]>
Signed-off-by: Derek McGowan <[email protected]>
95a218f to
315891d
Compare
Decouples the pkg/archive and pkg/system to prepare pkg/archive for moving.
This also allowed quite a bit of cleanup due to unnecessary interfaces and workarounds for older versions of the unix package.
pkg/archiveout of main module/repository #49069/pkg#32989