github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/builder/dockerfile/copy_unix.go (about)

     1  // +build !windows
     2  
     3  package dockerfile // import "github.com/docker/docker/builder/dockerfile"
     4  
     5  import (
     6  	"os"
     7  	"path/filepath"
     8  
     9  	"github.com/docker/docker/pkg/containerfs"
    10  	"github.com/docker/docker/pkg/idtools"
    11  )
    12  
    13  func fixPermissions(source, destination string, identity idtools.Identity, overrideSkip bool) error {
    14  	var (
    15  		skipChownRoot bool
    16  		err           error
    17  	)
    18  	if !overrideSkip {
    19  		destEndpoint := &copyEndpoint{driver: containerfs.NewLocalDriver(), path: destination}
    20  		skipChownRoot, err = isExistingDirectory(destEndpoint)
    21  		if err != nil {
    22  			return err
    23  		}
    24  	}
    25  
    26  	// We Walk on the source rather than on the destination because we don't
    27  	// want to change permissions on things we haven't created or modified.
    28  	return filepath.Walk(source, func(fullpath string, _ os.FileInfo, _ error) error {
    29  		// Do not alter the walk root iff. it existed before, as it doesn't fall under
    30  		// the domain of "things we should chown".
    31  		if skipChownRoot && source == fullpath {
    32  			return nil
    33  		}
    34  
    35  		// Path is prefixed by source: substitute with destination instead.
    36  		cleaned, err := filepath.Rel(source, fullpath)
    37  		if err != nil {
    38  			return err
    39  		}
    40  
    41  		fullpath = filepath.Join(destination, cleaned)
    42  		return os.Lchown(fullpath, identity.UID, identity.GID)
    43  	})
    44  }
    45  
    46  func validateCopySourcePath(imageSource *imageMount, origPath, platform string) error {
    47  	return nil
    48  }