2021-08-23 13:14:53 +00:00
|
|
|
//go:build !windows
|
2017-05-25 21:03:29 +00:00
|
|
|
// +build !windows
|
|
|
|
|
2018-02-05 21:05:59 +00:00
|
|
|
package dockerfile // import "github.com/docker/docker/builder/dockerfile"
|
2017-05-14 18:18:48 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2021-07-26 19:08:06 +00:00
|
|
|
"path"
|
2017-05-14 18:18:48 +00:00
|
|
|
"path/filepath"
|
2021-07-26 19:08:06 +00:00
|
|
|
"strings"
|
2017-05-14 18:18:48 +00:00
|
|
|
|
2017-08-04 00:22:00 +00:00
|
|
|
"github.com/docker/docker/pkg/containerfs"
|
2017-05-14 18:18:48 +00:00
|
|
|
"github.com/docker/docker/pkg/idtools"
|
|
|
|
)
|
|
|
|
|
2017-11-16 06:20:33 +00:00
|
|
|
func fixPermissions(source, destination string, identity idtools.Identity, overrideSkip bool) error {
|
2017-07-26 16:05:55 +00:00
|
|
|
var (
|
|
|
|
skipChownRoot bool
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if !overrideSkip {
|
2017-08-04 00:22:00 +00:00
|
|
|
destEndpoint := ©Endpoint{driver: containerfs.NewLocalDriver(), path: destination}
|
|
|
|
skipChownRoot, err = isExistingDirectory(destEndpoint)
|
2017-07-26 16:05:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-05-14 18:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We Walk on the source rather than on the destination because we don't
|
|
|
|
// want to change permissions on things we haven't created or modified.
|
2019-08-05 23:25:25 +00:00
|
|
|
return filepath.Walk(source, func(fullpath string, _ os.FileInfo, _ error) error {
|
2017-05-14 18:18:48 +00:00
|
|
|
// Do not alter the walk root iff. it existed before, as it doesn't fall under
|
|
|
|
// the domain of "things we should chown".
|
2017-05-25 21:03:29 +00:00
|
|
|
if skipChownRoot && source == fullpath {
|
2017-05-14 18:18:48 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Path is prefixed by source: substitute with destination instead.
|
|
|
|
cleaned, err := filepath.Rel(source, fullpath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fullpath = filepath.Join(destination, cleaned)
|
2017-11-16 06:20:33 +00:00
|
|
|
return os.Lchown(fullpath, identity.UID, identity.GID)
|
2017-05-14 18:18:48 +00:00
|
|
|
})
|
|
|
|
}
|
2017-08-04 00:22:00 +00:00
|
|
|
|
2021-07-26 19:08:06 +00:00
|
|
|
// normalizeDest normalises the destination of a COPY/ADD command in a
|
|
|
|
// platform semantically consistent way.
|
|
|
|
func normalizeDest(workingDir, requested string) (string, error) {
|
|
|
|
dest := filepath.FromSlash(requested)
|
|
|
|
endsInSlash := strings.HasSuffix(dest, string(os.PathSeparator))
|
|
|
|
|
|
|
|
if !path.IsAbs(requested) {
|
|
|
|
dest = path.Join("/", filepath.ToSlash(workingDir), dest)
|
|
|
|
// Make sure we preserve any trailing slash
|
|
|
|
if endsInSlash {
|
|
|
|
dest += "/"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dest, nil
|
|
|
|
}
|
|
|
|
|
2021-07-27 12:48:32 +00:00
|
|
|
func containsWildcards(name string) bool {
|
|
|
|
for i := 0; i < len(name); i++ {
|
|
|
|
ch := name[i]
|
|
|
|
if ch == '\\' {
|
|
|
|
i++
|
|
|
|
} else if ch == '*' || ch == '?' || ch == '[' {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-07-27 12:24:14 +00:00
|
|
|
func validateCopySourcePath(imageSource *imageMount, origPath string) error {
|
2017-08-04 00:22:00 +00:00
|
|
|
return nil
|
|
|
|
}
|