mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
vendor: update buildkit to master@ae9d0f5
Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
54
vendor/github.com/moby/buildkit/util/contentutil/buffer.go
generated
vendored
54
vendor/github.com/moby/buildkit/util/contentutil/buffer.go
generated
vendored
@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -18,12 +19,14 @@ import (
|
||||
type Buffer interface {
|
||||
content.Provider
|
||||
content.Ingester
|
||||
content.Manager
|
||||
}
|
||||
|
||||
// NewBuffer returns a new buffer
|
||||
func NewBuffer() Buffer {
|
||||
return &buffer{
|
||||
buffers: map[digest.Digest][]byte{},
|
||||
infos: map[digest.Digest]content.Info{},
|
||||
refs: map[string]struct{}{},
|
||||
}
|
||||
}
|
||||
@ -31,9 +34,59 @@ func NewBuffer() Buffer {
|
||||
type buffer struct {
|
||||
mu sync.Mutex
|
||||
buffers map[digest.Digest][]byte
|
||||
infos map[digest.Digest]content.Info
|
||||
refs map[string]struct{}
|
||||
}
|
||||
|
||||
func (b *buffer) Info(ctx context.Context, dgst digest.Digest) (content.Info, error) {
|
||||
b.mu.Lock()
|
||||
v, ok := b.infos[dgst]
|
||||
b.mu.Unlock()
|
||||
if !ok {
|
||||
return content.Info{}, errdefs.ErrNotFound
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func (b *buffer) Update(ctx context.Context, new content.Info, fieldpaths ...string) (content.Info, error) {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
|
||||
updated, ok := b.infos[new.Digest]
|
||||
if !ok {
|
||||
return content.Info{}, errdefs.ErrNotFound
|
||||
}
|
||||
|
||||
if len(fieldpaths) == 0 {
|
||||
fieldpaths = []string{"labels"}
|
||||
}
|
||||
|
||||
for _, path := range fieldpaths {
|
||||
if strings.HasPrefix(path, "labels.") {
|
||||
if updated.Labels == nil {
|
||||
updated.Labels = map[string]string{}
|
||||
}
|
||||
key := strings.TrimPrefix(path, "labels.")
|
||||
updated.Labels[key] = new.Labels[key]
|
||||
continue
|
||||
}
|
||||
if path == "labels" {
|
||||
updated.Labels = new.Labels
|
||||
}
|
||||
}
|
||||
|
||||
b.infos[new.Digest] = updated
|
||||
return updated, nil
|
||||
}
|
||||
|
||||
func (b *buffer) Walk(ctx context.Context, fn content.WalkFunc, filters ...string) error {
|
||||
return nil // not implemented
|
||||
}
|
||||
|
||||
func (b *buffer) Delete(ctx context.Context, dgst digest.Digest) error {
|
||||
return nil // not implemented
|
||||
}
|
||||
|
||||
func (b *buffer) Writer(ctx context.Context, opts ...content.WriterOpt) (content.Writer, error) {
|
||||
var wOpts content.WriterOpts
|
||||
for _, opt := range opts {
|
||||
@ -82,6 +135,7 @@ func (b *buffer) addValue(k digest.Digest, dt []byte) {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
b.buffers[k] = dt
|
||||
b.infos[k] = content.Info{Digest: k, Size: int64(len(dt))}
|
||||
}
|
||||
|
||||
type bufferedWriter struct {
|
||||
|
34
vendor/github.com/moby/buildkit/util/contentutil/source.go
generated
vendored
Normal file
34
vendor/github.com/moby/buildkit/util/contentutil/source.go
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
package contentutil
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/reference"
|
||||
)
|
||||
|
||||
func HasSource(info content.Info, refspec reference.Spec) (bool, error) {
|
||||
u, err := url.Parse("dummy://" + refspec.Locator)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if info.Labels == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
source, target := u.Hostname(), strings.TrimPrefix(u.Path, "/")
|
||||
repoLabel, ok := info.Labels["containerd.io/distribution.source."+source]
|
||||
if !ok || repoLabel == "" {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
for _, repo := range strings.Split(repoLabel, ",") {
|
||||
// the target repo is not a candidate
|
||||
if repo == target {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
Reference in New Issue
Block a user