Skip to content

Commit

Permalink
fileop: resolve review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed Feb 9, 2019
1 parent f7a3f5f commit be5f3a8
Show file tree
Hide file tree
Showing 4 changed files with 529 additions and 222 deletions.
25 changes: 13 additions & 12 deletions client/llb/fileop.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,10 @@ func (up *UserOpt) marshal(base pb.InputIndex) *pb.UserOpt {
return nil
}
if up.Name != "" {
return &pb.UserOpt{Name: up.Name, Input: base}
return &pb.UserOpt{User: &pb.UserOpt_ByName{ByName: &pb.NamedUserOpt{
Name: up.Name, Input: base}}}
}
return &pb.UserOpt{Id: uint32(up.UID), Input: -1}
return &pb.UserOpt{User: &pb.UserOpt_ByID{ByID: uint32(up.UID)}}
}

func Mkfile(p string, m os.FileMode, dt []byte, opts ...MkfileOption) *FileAction {
Expand Down Expand Up @@ -415,16 +416,16 @@ type fileActionCopy struct {

func (a *fileActionCopy) toProtoAction(parent string, base pb.InputIndex) pb.IsFileAction {
c := &pb.FileActionCopy{
Src: a.sourcePath(),
Dest: normalizePath(parent, a.dest),
Owner: a.info.ChownOpt.marshal(base),
AllowWildcard: a.info.AllowWildcard,
AllowEmptyWildcard: a.info.AllowEmptyWildcard,
FollowSymlink: a.info.FollowSymlinks,
DirCopyContents: a.info.CopyDirContentsOnly,
AttemptUnpack: a.info.AttemptUnpack,
CreateDestPath: a.info.CreateDestPath,
Timestamp: marshalTime(a.info.CreatedTime),
Src: a.sourcePath(),
Dest: normalizePath(parent, a.dest),
Owner: a.info.ChownOpt.marshal(base),
AllowWildcard: a.info.AllowWildcard,
AllowEmptyWildcard: a.info.AllowEmptyWildcard,
FollowSymlink: a.info.FollowSymlinks,
DirCopyContents: a.info.CopyDirContentsOnly,
AttemptUnpackDockerCompatibility: a.info.AttemptUnpack,
CreateDestPath: a.info.CreateDestPath,
Timestamp: marshalTime(a.info.CreatedTime),
}
if a.info.Mode != nil {
c.Mode = int32(*a.info.Mode)
Expand Down
42 changes: 15 additions & 27 deletions client/llb/fileop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,18 +478,14 @@ func TestFileOwner(t *testing.T) {

action = f.Actions[1]
mkdir = action.Action.(*pb.FileAction_Mkdir).Mkdir
require.Equal(t, 123, int(mkdir.Owner.User.Id))
require.Equal(t, "", mkdir.Owner.User.Name)
require.Equal(t, -1, int(mkdir.Owner.User.Input))
require.Equal(t, 456, int(mkdir.Owner.Group.Id))
require.Equal(t, "", mkdir.Owner.Group.Name)
require.Equal(t, -1, int(mkdir.Owner.Group.Input))
require.Equal(t, 123, int(mkdir.Owner.User.User.(*pb.UserOpt_ByID).ByID))
require.Equal(t, 456, int(mkdir.Owner.Group.User.(*pb.UserOpt_ByID).ByID))

action = f.Actions[2]
mkdir = action.Action.(*pb.FileAction_Mkdir).Mkdir
require.Equal(t, 0, int(mkdir.Owner.User.Id))
require.Equal(t, "foouser", mkdir.Owner.User.Name)
require.Equal(t, 0, int(mkdir.Owner.User.Input))

require.Equal(t, "foouser", mkdir.Owner.User.User.(*pb.UserOpt_ByName).ByName.Name)
require.Equal(t, 0, int(mkdir.Owner.User.User.(*pb.UserOpt_ByName).ByName.Input))
require.Nil(t, mkdir.Owner.Group)
}

Expand Down Expand Up @@ -524,44 +520,36 @@ func TestFileCopyOwner(t *testing.T) {

action := f.Actions[0]
mkdir := action.Action.(*pb.FileAction_Mkdir).Mkdir
require.Equal(t, 0, int(mkdir.Owner.User.Id))
require.Equal(t, "user1", mkdir.Owner.User.Name)
require.Equal(t, -1, int(mkdir.Owner.User.Input))
require.Equal(t, "user1", mkdir.Owner.User.User.(*pb.UserOpt_ByName).ByName.Name)
require.Equal(t, -1, int(mkdir.Owner.User.User.(*pb.UserOpt_ByName).ByName.Input))
require.Nil(t, mkdir.Owner.Group)

action = f.Actions[1]
copy := action.Action.(*pb.FileAction_Copy).Copy
require.Equal(t, "/src1", copy.Src)
require.Equal(t, 0, int(copy.Owner.User.Id))
require.Equal(t, "user2", copy.Owner.User.Name)
require.Equal(t, -1, int(copy.Owner.User.Input))
require.Equal(t, "user2", copy.Owner.User.User.(*pb.UserOpt_ByName).ByName.Name)
require.Equal(t, -1, int(copy.Owner.User.User.(*pb.UserOpt_ByName).ByName.Input))
require.Nil(t, copy.Owner.Group)

action = f.Actions[2]
copy = action.Action.(*pb.FileAction_Copy).Copy
require.Equal(t, "/src0", copy.Src)
require.Equal(t, 0, int(copy.Owner.User.Id))
require.Equal(t, "user3", copy.Owner.User.Name)
require.Equal(t, 0, int(copy.Owner.User.Input))
require.Equal(t, "user3", copy.Owner.User.User.(*pb.UserOpt_ByName).ByName.Name)
require.Equal(t, 0, int(copy.Owner.User.User.(*pb.UserOpt_ByName).ByName.Input))
require.Nil(t, copy.Owner.Group)

action = f.Actions[3]
copy = action.Action.(*pb.FileAction_Copy).Copy
require.Equal(t, "/src2", copy.Src)
require.Equal(t, 0, int(copy.Owner.User.Id))
require.Equal(t, "user4", copy.Owner.User.Name)
require.Equal(t, -1, int(copy.Owner.User.Input))
require.Equal(t, "user4", copy.Owner.User.User.(*pb.UserOpt_ByName).ByName.Name)
require.Equal(t, -1, int(copy.Owner.User.User.(*pb.UserOpt_ByName).ByName.Input))
require.Nil(t, copy.Owner.Group)

action = f.Actions[4]
copy = action.Action.(*pb.FileAction_Copy).Copy
require.Equal(t, "/src3", copy.Src)
require.Equal(t, 1, int(copy.Owner.User.Id))
require.Equal(t, "", copy.Owner.User.Name)
require.Equal(t, -1, int(copy.Owner.User.Input))
require.Equal(t, 2, int(copy.Owner.Group.Id))
require.Equal(t, "", copy.Owner.Group.Name)
require.Equal(t, -1, int(copy.Owner.Group.Input))
require.Equal(t, 1, int(copy.Owner.User.User.(*pb.UserOpt_ByID).ByID))
require.Equal(t, 2, int(copy.Owner.Group.User.(*pb.UserOpt_ByID).ByID))
}

func TestFileCreatedTime(t *testing.T) {
Expand Down
Loading

0 comments on commit be5f3a8

Please sign in to comment.