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-11-16 01:20:33 -05:00
|
|
|
func fixPermissions(source, destination string, identity idtools.Identity, overrideSkip bool) error {
|
2017-07-26 12:05:55 -04:00
|
|
|
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.
|
2019-08-05 19:25:25 -04:00
|
|
|
return filepath.Walk(source, func(fullpath string, _ os.FileInfo, _ error) error {
|
2017-05-14 14:18:48 -04: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 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)
|
2017-11-16 01:20:33 -05:00
|
|
|
return os.Lchown(fullpath, identity.UID, identity.GID)
|
2017-05-14 14:18:48 -04:00
|
|
|
})
|
|
|
|
}
|
2017-08-03 20:22:00 -04:00
|
|
|
|
|
|
|
func validateCopySourcePath(imageSource *imageMount, origPath, platform string) error {
|
|
|
|
return nil
|
|
|
|
}
|