Skip to content

Commit

Permalink
WIP/HACK: Add lots of filepath.ToFromSlash and system.FixWindowsPath
Browse files Browse the repository at this point in the history
I have no idea at which layers these things are supposed to be taken
care of, but I am super-suspicious of all the 'filepath.Join("/", path)'
calls.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
  • Loading branch information
TBBle committed Jul 24, 2020
1 parent 904d33b commit f1feab2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
17 changes: 15 additions & 2 deletions frontend/dockerfile/instructions/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package instructions

import (
"fmt"
"path/filepath"
"regexp"
"sort"
"strconv"
Expand All @@ -12,6 +13,7 @@ import (
"github.com/docker/docker/api/types/strslice"
"github.com/moby/buildkit/frontend/dockerfile/command"
"github.com/moby/buildkit/frontend/dockerfile/parser"
"github.com/moby/buildkit/util/system"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -243,8 +245,13 @@ func parseAdd(req parseRequest) (*AddCommand, error) {
if err := req.flags.Parse(); err != nil {
return nil, err
}
destPath, err := system.CheckSystemDriveAndRemoveDriveLetter(req.args[1])
if err != nil {
return nil, err
}
paths := append(req.args[:len(req.args)-1], filepath.ToSlash(destPath))
return &AddCommand{
SourcesAndDest: SourcesAndDest(req.args),
SourcesAndDest: paths,
withNameAndCode: newWithNameAndCode(req),
Chown: flChown.Value,
Chmod: flChmod.Value,
Expand Down Expand Up @@ -341,8 +348,14 @@ func parseWorkdir(req parseRequest) (*WorkdirCommand, error) {
if err != nil {
return nil, err
}

path, err := system.CheckSystemDriveAndRemoveDriveLetter(req.args[0])
if err != nil {
return nil, err
}

return &WorkdirCommand{
Path: req.args[0],
Path: filepath.ToSlash(path),
withNameAndCode: newWithNameAndCode(req),
}, nil

Expand Down
12 changes: 8 additions & 4 deletions solver/llbsolver/file/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func mapUserToChowner(user *copy.User, idmap *idtools.IdentityMapping) (copy.Cho
}

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

log.Printf("--- mkdir okay")
return nil
}

func mkfile(ctx context.Context, d string, action pb.FileActionMkFile, user *copy.User, idmap *idtools.IdentityMapping) error {
p, err := fs.RootPath(d, filepath.Join(filepath.Join("/", action.Path)))
p, err := fs.RootPath(filepath.ToSlash(d), filepath.ToSlash(filepath.Join(filepath.Join("/", action.Path))))
if err != nil {
return err
}
p = filepath.FromSlash(p)

ch, err := mapUserToChowner(user, idmap)
if err != nil {
Expand Down Expand Up @@ -146,10 +148,11 @@ func rm(ctx context.Context, d string, action pb.FileActionRm) error {
}

func rmPath(root, src string, allowNotFound bool) error {
p, err := fs.RootPath(root, filepath.Join(filepath.Join("/", src)))
p, err := fs.RootPath(filepath.ToSlash(root), filepath.ToSlash(filepath.Join(filepath.Join("/", src))))
if err != nil {
return err
}
p = filepath.FromSlash(p)

if err := os.RemoveAll(p); err != nil {
if errors.Is(err, os.ErrNotExist) && allowNotFound {
Expand All @@ -166,10 +169,11 @@ 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 := fs.RootPath(filepath.ToSlash(dest), filepath.ToSlash(filepath.Join(filepath.Join("/", action.Dest))))
if err != nil {
return err
}
p = filepath.FromSlash(p)
if _, err := os.Lstat(filepath.Dir(p)); err != nil {
return errors.Wrapf(err, "failed to stat %s", action.Dest)
}
Expand Down

0 comments on commit f1feab2

Please sign in to comment.