Skip to content

Commit

Permalink
Refactor RootPath into helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
hinshun committed Oct 30, 2019
1 parent c464a03 commit 4abbddf
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions solver/llbsolver/file/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func mapUser(user *copy.ChownOpt, idmap *idtools.IdentityMapping) (*copy.ChownOp
}

func mkdir(ctx context.Context, d string, action pb.FileActionMkDir, user *copy.ChownOpt, idmap *idtools.IdentityMapping) error {
p, err := fs.RootPath(d, filepath.Join(filepath.Join("/", action.Path)))
p, err := rootPath(d, action.Path)
if err != nil {
return err
}
Expand Down Expand Up @@ -74,7 +74,7 @@ func mkdir(ctx context.Context, d string, action pb.FileActionMkDir, user *copy.
}

func mkfile(ctx context.Context, d string, action pb.FileActionMkFile, user *copy.ChownOpt, idmap *idtools.IdentityMapping) error {
p, err := fs.RootPath(d, filepath.Join(filepath.Join("/", action.Path)))
p, err := rootPath(d, action.Path)
if err != nil {
return err
}
Expand Down Expand Up @@ -108,7 +108,7 @@ func rm(ctx context.Context, d string, action pb.FileActionRm) error {
}

for _, s := range m {
p, err := fs.RootPath(d, filepath.Join(filepath.Join("/", s)))
p, err := rootPath(d, s)
if err != nil {
return err
}
Expand All @@ -121,7 +121,7 @@ func rm(ctx context.Context, d string, action pb.FileActionRm) error {
return nil
}

p, err := fs.RootPath(d, filepath.Join(filepath.Join("/", action.Path)))
p, err := rootPath(d, action.Path)
if err != nil {
return err
}
Expand All @@ -141,7 +141,7 @@ func docopy(ctx context.Context, src, dest string, action pb.FileActionCopy, u *
destPath := cleanPath(action.Dest)

if !action.CreateDestPath {
p, err := fs.RootPath(dest, filepath.Join(filepath.Join("/", action.Dest)))
p, err := rootPath(dest, action.Dest)
if err != nil {
return err
}
Expand Down Expand Up @@ -225,6 +225,10 @@ func cleanPath(s string) string {
return s2
}

func rootPath(root, src string) (string, error) {
return fs.RootPath(root, filepath.Join(filepath.Join("/", src)))
}

type Backend struct {
}

Expand Down

0 comments on commit 4abbddf

Please sign in to comment.