Skip to content

Commit 805b993

Browse files
Revert most changes to client/llb
Signed-off-by: Gabriel Adrian Samfira <[email protected]>
1 parent 45b4617 commit 805b993

File tree

3 files changed

+40
-50
lines changed

3 files changed

+40
-50
lines changed

client/llb/fileop.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import (
44
"context"
55
_ "crypto/sha256" // for opencontainers/go-digest
66
"os"
7+
"path"
78
"path/filepath"
89
"strconv"
910
"strings"
1011
"time"
1112

1213
"github.com/moby/buildkit/solver/pb"
13-
"github.com/moby/buildkit/util/system"
1414
digest "github.com/opencontainers/go-digest"
1515
"github.com/pkg/errors"
1616
)
@@ -55,7 +55,7 @@ type CopyInput interface {
5555
}
5656

5757
type subAction interface {
58-
toProtoAction(ctx context.Context, parent string, base pb.InputIndex, platformOS string) (pb.IsFileAction, error)
58+
toProtoAction(context.Context, string, pb.InputIndex) (pb.IsFileAction, error)
5959
}
6060

6161
type capAdder interface {
@@ -146,6 +146,7 @@ func Mkdir(p string, m os.FileMode, opt ...MkdirOption) *FileAction {
146146
for _, o := range opt {
147147
o.SetMkdirOption(&mi)
148148
}
149+
149150
return &FileAction{
150151
action: &fileActionMkdir{
151152
file: p,
@@ -161,14 +162,10 @@ type fileActionMkdir struct {
161162
info MkdirInfo
162163
}
163164

164-
func (a *fileActionMkdir) toProtoAction(ctx context.Context, parent string, base pb.InputIndex, platformOS string) (pb.IsFileAction, error) {
165-
normalizedPath, err := system.NormalizePath(parent, a.file, platformOS, false)
166-
if err != nil {
167-
return nil, errors.Wrap(err, "normalizing path")
168-
}
165+
func (a *fileActionMkdir) toProtoAction(ctx context.Context, parent string, base pb.InputIndex) (pb.IsFileAction, error) {
169166
return &pb.FileAction_Mkdir{
170167
Mkdir: &pb.FileActionMkDir{
171-
Path: normalizedPath,
168+
Path: normalizePath(parent, a.file, false),
172169
Mode: int32(a.mode & 0777),
173170
MakeParents: a.info.MakeParents,
174171
Owner: a.info.ChownOpt.marshal(base),
@@ -339,14 +336,10 @@ type fileActionMkfile struct {
339336
info MkfileInfo
340337
}
341338

342-
func (a *fileActionMkfile) toProtoAction(ctx context.Context, parent string, base pb.InputIndex, platformOS string) (pb.IsFileAction, error) {
343-
normalizedPath, err := system.NormalizePath(parent, a.file, platformOS, false)
344-
if err != nil {
345-
return nil, errors.Wrap(err, "normalizing path")
346-
}
339+
func (a *fileActionMkfile) toProtoAction(ctx context.Context, parent string, base pb.InputIndex) (pb.IsFileAction, error) {
347340
return &pb.FileAction_Mkfile{
348341
Mkfile: &pb.FileActionMkFile{
349-
Path: normalizedPath,
342+
Path: normalizePath(parent, a.file, false),
350343
Mode: int32(a.mode & 0777),
351344
Data: a.dt,
352345
Owner: a.info.ChownOpt.marshal(base),
@@ -411,14 +404,10 @@ type fileActionRm struct {
411404
info RmInfo
412405
}
413406

414-
func (a *fileActionRm) toProtoAction(ctx context.Context, parent string, base pb.InputIndex, platformOS string) (pb.IsFileAction, error) {
415-
normalizedPath, err := system.NormalizePath(parent, a.file, platformOS, false)
416-
if err != nil {
417-
return nil, errors.Wrap(err, "normalizing path")
418-
}
407+
func (a *fileActionRm) toProtoAction(ctx context.Context, parent string, base pb.InputIndex) (pb.IsFileAction, error) {
419408
return &pb.FileAction_Rm{
420409
Rm: &pb.FileActionRm{
421-
Path: normalizedPath,
410+
Path: normalizePath(parent, a.file, false),
422411
AllowNotFound: a.info.AllowNotFound,
423412
AllowWildcard: a.info.AllowWildcard,
424413
},
@@ -504,18 +493,14 @@ type fileActionCopy struct {
504493
info CopyInfo
505494
}
506495

507-
func (a *fileActionCopy) toProtoAction(ctx context.Context, parent string, base pb.InputIndex, platformOS string) (pb.IsFileAction, error) {
508-
src, err := a.sourcePath(ctx, platformOS)
496+
func (a *fileActionCopy) toProtoAction(ctx context.Context, parent string, base pb.InputIndex) (pb.IsFileAction, error) {
497+
src, err := a.sourcePath(ctx)
509498
if err != nil {
510499
return nil, err
511500
}
512-
normalizedPath, err := system.NormalizePath(parent, a.dest, platformOS, false)
513-
if err != nil {
514-
return nil, errors.Wrap(err, "normalizing path")
515-
}
516501
c := &pb.FileActionCopy{
517502
Src: src,
518-
Dest: normalizedPath,
503+
Dest: normalizePath(parent, a.dest, true),
519504
Owner: a.info.ChownOpt.marshal(base),
520505
IncludePatterns: a.info.IncludePatterns,
521506
ExcludePatterns: a.info.ExcludePatterns,
@@ -537,13 +522,13 @@ func (a *fileActionCopy) toProtoAction(ctx context.Context, parent string, base
537522
}, nil
538523
}
539524

540-
func (a *fileActionCopy) sourcePath(ctx context.Context, platform string) (string, error) {
525+
func (a *fileActionCopy) sourcePath(ctx context.Context) (string, error) {
541526
// filepath.Clean() also does a filepath.FromSlash(). Explicitly convert back to UNIX path
542527
// separators.
543528
p := filepath.ToSlash(filepath.Clean(a.src))
544529
dir := "/"
545530
var err error
546-
if !system.IsAbs(p, platform) {
531+
if !path.IsAbs(p) {
547532
if a.state != nil {
548533
dir, err = a.state.GetDir(ctx)
549534
} else if a.fas != nil {
@@ -553,11 +538,7 @@ func (a *fileActionCopy) sourcePath(ctx context.Context, platform string) (strin
553538
return "", err
554539
}
555540
}
556-
p, err = system.NormalizePath(dir, p, platform, false)
557-
if err != nil {
558-
return "", errors.Wrap(err, "normalizing source path")
559-
}
560-
return p, nil
541+
return path.Join(dir, p), nil
561542
}
562543

563544
func (a *fileActionCopy) addCaps(f *FileOp) {
@@ -772,7 +753,7 @@ func (f *FileOp) Marshal(ctx context.Context, c *Constraints) (digest.Digest, []
772753
}
773754
}
774755

775-
action, err := st.action.toProtoAction(ctx, parent, st.base, f.constraints.Platform.OS)
756+
action, err := st.action.toProtoAction(ctx, parent, st.base)
776757
if err != nil {
777758
return "", nil, nil, nil, err
778759
}
@@ -793,6 +774,25 @@ func (f *FileOp) Marshal(ctx context.Context, c *Constraints) (digest.Digest, []
793774
return f.Load()
794775
}
795776

777+
func normalizePath(parent, p string, keepSlash bool) string {
778+
origPath := p
779+
p = path.Clean(p)
780+
if !path.IsAbs(p) {
781+
p = path.Join("/", parent, p)
782+
}
783+
if keepSlash {
784+
if strings.HasSuffix(origPath, "/") && !strings.HasSuffix(p, "/") {
785+
p += "/"
786+
} else if strings.HasSuffix(origPath, "/.") {
787+
if p != "/" {
788+
p += "/"
789+
}
790+
p += "."
791+
}
792+
}
793+
return p
794+
}
795+
796796
func (f *FileOp) Output() Output {
797797
return f.output
798798
}

client/llb/meta.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import (
44
"context"
55
"fmt"
66
"net"
7+
"path"
78

89
"github.com/containerd/containerd/platforms"
910
"github.com/google/shlex"
1011
"github.com/moby/buildkit/solver/pb"
11-
"github.com/moby/buildkit/util/system"
1212
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
1313
"github.com/pkg/errors"
1414
)
@@ -76,19 +76,15 @@ func dirf(value string, replace bool, v ...interface{}) StateOption {
7676
}
7777
return func(s State) State {
7878
return s.withValue(keyDir, func(ctx context.Context, c *Constraints) (interface{}, error) {
79-
platform := "linux"
80-
if c != nil && c.Platform != nil {
81-
platform = c.Platform.OS
82-
}
83-
if !system.IsAbs(value, platform) {
79+
if !path.IsAbs(value) {
8480
prev, err := getDir(s)(ctx, c)
8581
if err != nil {
8682
return nil, errors.Wrap(err, "getting dir from state")
8783
}
88-
value, err = system.NormalizePath(prev, value, platform, false)
89-
if err != nil {
90-
return nil, errors.Wrap(err, "normalizing path")
84+
if prev == "" {
85+
prev = "/"
9186
}
87+
value = path.Join(prev, value)
9288
}
9389
return value, nil
9490
})

client/llb/state.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,6 @@ func (s State) File(a *FileAction, opts ...ConstraintsOpt) State {
299299
o.SetConstraintsOption(&c)
300300
}
301301

302-
// No platform was set by constraint options. Set the current OS and arch.
303-
if c.Platform == nil {
304-
c.Platform = &ocispecs.Platform{
305-
OS: "linux",
306-
}
307-
}
308302
return s.WithOutput(NewFileOp(s, a, c).Output())
309303
}
310304

0 commit comments

Comments
 (0)