-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add FileActionSymlink and llb.Symlink
#5519
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,13 @@ func (fa *FileAction) Mkfile(p string, m os.FileMode, dt []byte, opt ...MkfileOp | |
return a | ||
} | ||
|
||
// Symlink creates a symlink at `newpath` that points to `oldpath` | ||
func (fa *FileAction) Symlink(oldpath, newpath string, opt ...SymlinkOption) *FileAction { | ||
a := Symlink(oldpath, newpath, opt...) | ||
a.prev = fa | ||
return a | ||
} | ||
|
||
func (fa *FileAction) Rm(p string, opt ...RmOption) *FileAction { | ||
a := Rm(p, opt...) | ||
a.prev = fa | ||
|
@@ -193,6 +200,7 @@ type ChownOption interface { | |
MkdirOption | ||
MkfileOption | ||
CopyOption | ||
SymlinkOption | ||
} | ||
|
||
type mkdirOptionFunc func(*MkdirInfo) | ||
|
@@ -290,6 +298,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 | ||
|
@@ -337,6 +349,57 @@ func Mkfile(p string, m os.FileMode, dt []byte, opts ...MkfileOption) *FileActio | |
} | ||
} | ||
|
||
// SymlinkInfo is the modifiable options used to create symlinks | ||
type SymlinkInfo struct { | ||
ChownOpt *ChownOpt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the man pages, symlink permissions are irrelevant. Is the mode for the SUID, SGID, and sticky bits? What effect do those have on symlinks? |
||
CreatedTime *time.Time | ||
} | ||
|
||
func (si *SymlinkInfo) SetSymlinkOption(si2 *SymlinkInfo) { | ||
*si2 = *si | ||
} | ||
|
||
type SymlinkOption interface { | ||
SetSymlinkOption(*SymlinkInfo) | ||
} | ||
|
||
// Symlink creates a symlink at `newpath` that points to `oldpath` | ||
func Symlink(oldpath, newpath string, opts ...SymlinkOption) *FileAction { | ||
var si SymlinkInfo | ||
for _, o := range opts { | ||
o.SetSymlinkOption(&si) | ||
} | ||
|
||
return &FileAction{ | ||
action: &fileActionSymlink{ | ||
oldpath: oldpath, | ||
newpath: newpath, | ||
info: si, | ||
}, | ||
} | ||
} | ||
|
||
type fileActionSymlink struct { | ||
oldpath string | ||
newpath string | ||
info SymlinkInfo | ||
} | ||
|
||
func (s *fileActionSymlink) addCaps(f *FileOp) { | ||
addCap(&f.constraints, pb.CapFileSymlinkCreate) | ||
} | ||
|
||
func (s *fileActionSymlink) toProtoAction(_ context.Context, _ string, base pb.InputIndex) (pb.IsFileAction, error) { | ||
return &pb.FileAction_Symlink{ | ||
Symlink: &pb.FileActionSymlink{ | ||
Oldpath: s.oldpath, | ||
Newpath: s.newpath, | ||
Owner: s.info.ChownOpt.marshal(base), | ||
Timestamp: marshalTime(s.info.CreatedTime), | ||
}, | ||
}, nil | ||
} | ||
|
||
type MkfileOption interface { | ||
SetMkfileOption(*MkfileInfo) | ||
} | ||
|
@@ -606,6 +669,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) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this check that it is a symlink and that it points to the correct location?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted, will fix this by checking
header.Linkname
and verifying its destination.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
header.Typeflag
symlink check as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.