2017-05-25 17:03:29 -04:00
|
|
|
// +build !windows
|
|
|
|
|
2018-02-05 16:05:59 -05:00
|
|
|
package dockerfile // import "github.com/docker/docker/builder/dockerfile"
|
2017-05-14 14:18:48 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2017-08-03 20:22:00 -04:00
|
|
|
"github.com/docker/docker/pkg/containerfs"
|
2017-05-14 14:18:48 -04:00
|
|
|
"github.com/docker/docker/pkg/idtools"
|
|
|
|
)
|
|
|
|
|
2017-07-26 12:05:55 -04:00
|
|
|
func fixPermissions(source, destination string, rootIDs idtools.IDPair, overrideSkip bool) error {
|
|
|
|
var (
|
|
|
|
skipChownRoot bool
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if !overrideSkip {
|
2017-08-03 20:22:00 -04:00
|
|
|
destEndpoint := ©Endpoint{driver: containerfs.NewLocalDriver(), path: destination}
|
|
|
|
skipChownRoot, err = isExistingDirectory(destEndpoint)
|
2017-07-26 12:05:55 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-05-14 14:18:48 -04: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.
|
|
|
|
return filepath.Walk(source, func(fullpath string, info os.FileInfo, err error) error {
|
|
|
|
// 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 17:03:29 -04:00
|
|
|
if skipChownRoot && source == fullpath {
|
2017-05-14 14:18:48 -04: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)
|
|
|
|
return os.Lchown(fullpath, rootIDs.UID, rootIDs.GID)
|
|
|
|
})
|
|
|
|
}
|
2017-08-03 20:22:00 -04:00
|
|
|
|
|
|
|
func validateCopySourcePath(imageSource *imageMount, origPath, platform string) error {
|
|
|
|
return nil
|
|
|
|
}
|