vendor: update buildkit to master@c36941f4a10e

Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
Justin Chadwell
2023-05-30 09:10:52 +01:00
parent 17bdbbd3c3
commit 6c62225d1b
141 changed files with 1402 additions and 1161 deletions

View File

@ -205,7 +205,8 @@ func (dw *DiskWriter) HandleChange(kind ChangeKind, p string, fi os.FileInfo, er
return errors.Wrapf(err, "failed to remove %s", destPath)
}
}
if err := os.Rename(newPath, destPath); err != nil {
if err := renameFile(newPath, destPath); err != nil {
return errors.Wrapf(err, "failed to rename %s to %s", newPath, destPath)
}
}

View File

@ -51,3 +51,10 @@ func handleTarTypeBlockCharFifo(path string, stat *types.Stat) error {
}
return nil
}
func renameFile(src, dst string) error {
if err := os.Rename(src, dst); err != nil {
return errors.Wrapf(err, "failed to rename %s to %s", src, dst)
}
return nil
}

View File

@ -1,8 +1,15 @@
//go:build windows
// +build windows
package fsutil
import (
"fmt"
iofs "io/fs"
"os"
"syscall"
"github.com/Microsoft/go-winio"
"github.com/pkg/errors"
"github.com/tonistiigi/fsutil/types"
)
@ -16,3 +23,75 @@ func rewriteMetadata(p string, stat *types.Stat) error {
func handleTarTypeBlockCharFifo(path string, stat *types.Stat) error {
return errors.New("Not implemented on windows")
}
func getFileHandle(path string, info iofs.FileInfo) (syscall.Handle, error) {
p, err := syscall.UTF16PtrFromString(path)
if err != nil {
return 0, errors.Wrap(err, "converting string to UTF-16")
}
attrs := uint32(syscall.FILE_FLAG_BACKUP_SEMANTICS)
if info.Mode()&os.ModeSymlink != 0 {
// Use FILE_FLAG_OPEN_REPARSE_POINT, otherwise CreateFile will follow symlink.
// See https://docs.microsoft.com/en-us/windows/desktop/FileIO/symbolic-link-effects-on-file-systems-functions#createfile-and-createfiletransacted
attrs |= syscall.FILE_FLAG_OPEN_REPARSE_POINT
}
h, err := syscall.CreateFile(p, 0, 0, nil, syscall.OPEN_EXISTING, attrs, 0)
if err != nil {
return 0, errors.Wrap(err, "getting file handle")
}
return h, nil
}
func readlink(path string, info iofs.FileInfo) ([]byte, error) {
h, err := getFileHandle(path, info)
if err != nil {
return nil, errors.Wrap(err, "getting file handle")
}
defer syscall.CloseHandle(h)
rdbbuf := make([]byte, syscall.MAXIMUM_REPARSE_DATA_BUFFER_SIZE)
var bytesReturned uint32
err = syscall.DeviceIoControl(h, syscall.FSCTL_GET_REPARSE_POINT, nil, 0, &rdbbuf[0], uint32(len(rdbbuf)), &bytesReturned, nil)
if err != nil {
return nil, errors.Wrap(err, "sending I/O control command")
}
return rdbbuf[:bytesReturned], nil
}
func getReparsePoint(path string, info iofs.FileInfo) (*winio.ReparsePoint, error) {
target, err := readlink(path, info)
if err != nil {
return nil, errors.Wrap(err, "fetching link")
}
rp, err := winio.DecodeReparsePoint(target)
if err != nil {
return nil, errors.Wrap(err, "decoding reparse point")
}
return rp, nil
}
func renameFile(src, dst string) error {
info, err := os.Lstat(dst)
if err != nil {
if !os.IsNotExist(err) {
return errors.Wrap(err, "getting file info")
}
}
if info != nil && info.Mode()&os.ModeSymlink != 0 {
dstInfoRp, err := getReparsePoint(dst, info)
if err != nil {
return errors.Wrap(err, "getting reparse point")
}
if dstInfoRp.IsMountPoint {
return fmt.Errorf("%s is a mount point", dst)
}
if err := os.Remove(dst); err != nil {
return errors.Wrapf(err, "removing %s", dst)
}
}
if err := os.Rename(src, dst); err != nil {
return errors.Wrapf(err, "failed to rename %s to %s", src, dst)
}
return nil
}

View File

@ -19,7 +19,7 @@ func FollowLinks(root string, paths []string) ([]string, error) {
}
res := make([]string, 0, len(r.resolved))
for r := range r.resolved {
res = append(res, r)
res = append(res, filepath.ToSlash(r))
}
sort.Strings(res)
return dedupePaths(res), nil
@ -31,6 +31,12 @@ type symlinkResolver struct {
}
func (r *symlinkResolver) append(p string) error {
if runtime.GOOS == "windows" && filepath.IsAbs(filepath.FromSlash(p)) {
absParts := strings.SplitN(p, ":", 2)
if len(absParts) == 2 {
p = absParts[1]
}
}
p = filepath.Join(".", p)
current := "."
for {
@ -41,7 +47,6 @@ func (r *symlinkResolver) append(p string) error {
if err != nil {
return err
}
p = ""
if len(parts) == 2 {
p = parts[1]
@ -76,7 +81,7 @@ func (r *symlinkResolver) readSymlink(p string, allowWildcard bool) ([]string, e
if allowWildcard && containsWildcards(base) {
fis, err := os.ReadDir(filepath.Dir(realPath))
if err != nil {
if errors.Is(err, os.ErrNotExist) {
if isNotFound(err) {
return nil, nil
}
return nil, errors.Wrap(err, "readdir")
@ -96,7 +101,7 @@ func (r *symlinkResolver) readSymlink(p string, allowWildcard bool) ([]string, e
fi, err := os.Lstat(realPath)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
if isNotFound(err) {
return nil, nil
}
return nil, errors.WithStack(err)
@ -139,7 +144,7 @@ func dedupePaths(in []string) []string {
if s == "." {
return nil
}
if strings.HasPrefix(s, last+string(filepath.Separator)) {
if strings.HasPrefix(s, last+"/") {
continue
}
out = append(out, s)

View File

@ -0,0 +1,14 @@
//go:build !windows
// +build !windows
package fsutil
import (
"os"
"github.com/pkg/errors"
)
func isNotFound(err error) bool {
return errors.Is(err, os.ErrNotExist)
}

View File

@ -0,0 +1,15 @@
package fsutil
import (
"os"
"github.com/pkg/errors"
"golang.org/x/sys/windows"
)
func isNotFound(err error) bool {
if errors.Is(err, os.ErrNotExist) || errors.Is(err, windows.ERROR_INVALID_NAME) {
return true
}
return false
}