github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/builder/dockerfile/copy_unix.go (about)

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