github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/builder/dockerfile/copy_unix.go (about)

     1  // +build !windows
     2  
     3  package dockerfile // import "github.com/demonoid81/moby/builder/dockerfile"
     4  
     5  import (
     6  	"os"
     7  	"path/filepath"
     8  
     9  	"github.com/demonoid81/moby/pkg/containerfs"
    10  	"github.com/demonoid81/moby/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  }