builder/dockerfile/copy_unix.go
51360965
 // +build !windows
 
bd5f92d2
 package dockerfile
 
 import (
 	"os"
 	"path/filepath"
 
7a7357da
 	"github.com/docker/docker/pkg/containerfs"
bd5f92d2
 	"github.com/docker/docker/pkg/idtools"
 )
 
19a29f6f
 func fixPermissions(source, destination string, rootIDs idtools.IDPair, overrideSkip bool) error {
 	var (
 		skipChownRoot bool
 		err           error
 	)
 	if !overrideSkip {
7a7357da
 		destEndpoint := &copyEndpoint{driver: containerfs.NewLocalDriver(), path: destination}
 		skipChownRoot, err = isExistingDirectory(destEndpoint)
19a29f6f
 		if err != nil {
 			return err
 		}
bd5f92d2
 	}
 
 	// 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".
51360965
 		if skipChownRoot && source == fullpath {
bd5f92d2
 			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)
 	})
 }
7a7357da
 
 func validateCopySourcePath(imageSource *imageMount, origPath, platform string) error {
 	return nil
 }