Skip to content

Commit

Permalink
Expose symlink options to llb package
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Engelbert <[email protected]>
  • Loading branch information
pmengelbert committed Nov 19, 2024
1 parent 8889296 commit 61b3374
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
47 changes: 36 additions & 11 deletions client/llb/fileop.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func (fa *FileAction) Mkfile(p string, m os.FileMode, dt []byte, opt ...MkfileOp
return a
}

func (fa *FileAction) Symlink(target, src string) *FileAction {
a := Symlink(target, src)
func (fa *FileAction) Symlink(target, src string, opt ...SymlinkOption) *FileAction {
a := Symlink(target, src, opt...)
a.prev = fa
return a
}
Expand Down Expand Up @@ -198,6 +198,7 @@ type ChownOption interface {
MkdirOption
MkfileOption
CopyOption
SymlinkOption
}

type mkdirOptionFunc func(*MkdirInfo)
Expand Down Expand Up @@ -295,6 +296,10 @@ func (co ChownOpt) SetCopyOption(mi *CopyInfo) {
mi.ChownOpt = &co
}

func (co ChownOpt) SetSymlinkOption(si *SymlinkInfo) {
si.ChownOpt = &co
}

func (co *ChownOpt) marshal(base pb.InputIndex) *pb.ChownOpt {
if co == nil {
return nil
Expand Down Expand Up @@ -342,31 +347,47 @@ func Mkfile(p string, m os.FileMode, dt []byte, opts ...MkfileOption) *FileActio
}
}

type SymlinkInfo struct{}
type SymlinkInfo struct {
ChownOpt *ChownOpt
CreatedTime *time.Time
}

func (si *SymlinkInfo) SetSymlinkOption(si2 *SymlinkInfo) {
*si2 = *si
}

type SymlinkOption interface {
SetSymlinkOption(*SymlinkInfo)
}

func Symlink(target, src string) *FileAction {
func Symlink(target, src string, opts ...SymlinkOption) *FileAction {
var si SymlinkInfo
for _, o := range opts {
o.SetSymlinkOption(&si)
}

return &FileAction{
action: &fileActionSymlink{
target: target,
src: src,
target: target,
src: src,
info: si,
},
}
}

type fileActionSymlink struct {
target string
src string
target string
src string
info SymlinkInfo
}

func (f *fileActionSymlink) toProtoAction(_ context.Context, _ string, _ pb.InputIndex) (pb.IsFileAction, error) {
func (f *fileActionSymlink) toProtoAction(_ context.Context, _ string, base pb.InputIndex) (pb.IsFileAction, error) {
return &pb.FileAction_Symlink{
Symlink: &pb.FileActionSymlink{
Target: f.target,
Src: f.src,
Target: f.target,
Src: f.src,
Owner: f.info.ChownOpt.marshal(base),
Timestamp: marshalTime(f.info.CreatedTime),
},
}, nil
}
Expand Down Expand Up @@ -640,6 +661,10 @@ func (c CreatedTime) SetMkfileOption(mi *MkfileInfo) {
mi.CreatedTime = (*time.Time)(&c)
}

func (c CreatedTime) SetSymlinkOption(si *SymlinkInfo) {
si.CreatedTime = (*time.Time)(&c)
}

func (c CreatedTime) SetCopyOption(mi *CopyInfo) {
mi.CreatedTime = (*time.Time)(&c)
}
Expand Down
2 changes: 1 addition & 1 deletion solver/llbsolver/ops/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ func (b *testFileBackend) Mkfile(_ context.Context, m, user, group fileoptypes.M
return nil
}

func (b *testFileBackend) Symlink(_ context.Context, m fileoptypes.Mount, a *pb.FileActionSymlink) error {
func (b *testFileBackend) Symlink(_ context.Context, m, user, group fileoptypes.Mount, a *pb.FileActionSymlink) error {
mm := m.(*testMount)
mm.id += "-mkfile"
mm.chain = append(mm.chain, mod{symlink: a})
Expand Down

0 comments on commit 61b3374

Please sign in to comment.