mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-28 08:27:42 +08:00

v0.7.2 ---------------- Fixes: - solver: gracefully handle cache loading errors - remotecache: only visit each item once when walking results - cache: avoid possible nil dereference on error handling - contenthash: allow security.capability in cache checksum - contenthash: treat unix sockets as regular files - push: fix race condition on pushing the same layers in parallel - inline cache: fix handling of duplicate blobs in same image - gateway: fix metadata getting lost on subsolve in external frontend - filesync: avoid ignoring close error - runc: update runc binary to v1.0.0-rc91 - buildctl-daemonless: allow max retries on socket connect for buildctl - buildctl-daemonless: fix shell args expansion - buildctl-daemonless: show log on startup timeout v0.7.1 ---------------- Fixes: - git: use --force flag on fetch - tar exporter: handle symlinks properly - resolver: disable http2 for pushing Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
77 lines
1.5 KiB
Go
77 lines
1.5 KiB
Go
package fsutil
|
|
|
|
import (
|
|
"archive/tar"
|
|
"context"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/tonistiigi/fsutil/types"
|
|
)
|
|
|
|
func WriteTar(ctx context.Context, fs FS, w io.Writer) error {
|
|
tw := tar.NewWriter(w)
|
|
err := fs.Walk(ctx, func(path string, fi os.FileInfo, err error) error {
|
|
stat, ok := fi.Sys().(*types.Stat)
|
|
if !ok {
|
|
return errors.Wrapf(err, "invalid fileinfo without stat info: %s", path)
|
|
}
|
|
hdr, err := tar.FileInfoHeader(fi, stat.Linkname)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
name := filepath.ToSlash(path)
|
|
if fi.IsDir() && !strings.HasSuffix(name, "/") {
|
|
name += "/"
|
|
}
|
|
hdr.Name = name
|
|
|
|
hdr.Uid = int(stat.Uid)
|
|
hdr.Gid = int(stat.Gid)
|
|
hdr.Devmajor = stat.Devmajor
|
|
hdr.Devminor = stat.Devminor
|
|
hdr.Linkname = stat.Linkname
|
|
if hdr.Linkname != "" {
|
|
hdr.Size = 0
|
|
if fi.Mode() & os.ModeSymlink != 0 {
|
|
hdr.Typeflag = tar.TypeSymlink
|
|
} else {
|
|
hdr.Typeflag = tar.TypeLink
|
|
}
|
|
}
|
|
|
|
if len(stat.Xattrs) > 0 {
|
|
hdr.PAXRecords = map[string]string{}
|
|
}
|
|
for k, v := range stat.Xattrs {
|
|
hdr.PAXRecords["SCHILY.xattr."+k] = string(v)
|
|
}
|
|
|
|
if err := tw.WriteHeader(hdr); err != nil {
|
|
return errors.Wrap(err, "failed to write file header")
|
|
}
|
|
|
|
if hdr.Typeflag == tar.TypeReg && hdr.Size > 0 && hdr.Linkname == "" {
|
|
rc, err := fs.Open(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if _, err := io.Copy(tw, rc); err != nil {
|
|
return err
|
|
}
|
|
if err := rc.Close(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return tw.Close()
|
|
}
|