github.com/docker/engine@v22.0.0-20211208180946-d456264580cf+incompatible/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" 9 "path/filepath" 10 "strings" 11 12 "github.com/docker/docker/pkg/containerfs" 13 "github.com/docker/docker/pkg/idtools" 14 ) 15 16 func fixPermissions(source, destination string, identity idtools.Identity, overrideSkip bool) error { 17 var ( 18 skipChownRoot bool 19 err error 20 ) 21 if !overrideSkip { 22 destEndpoint := ©Endpoint{driver: containerfs.NewLocalDriver(), path: destination} 23 skipChownRoot, err = isExistingDirectory(destEndpoint) 24 if err != nil { 25 return err 26 } 27 } 28 29 // We Walk on the source rather than on the destination because we don't 30 // want to change permissions on things we haven't created or modified. 31 return filepath.Walk(source, func(fullpath string, _ os.FileInfo, _ error) error { 32 // Do not alter the walk root iff. it existed before, as it doesn't fall under 33 // the domain of "things we should chown". 34 if skipChownRoot && source == fullpath { 35 return nil 36 } 37 38 // Path is prefixed by source: substitute with destination instead. 39 cleaned, err := filepath.Rel(source, fullpath) 40 if err != nil { 41 return err 42 } 43 44 fullpath = filepath.Join(destination, cleaned) 45 return os.Lchown(fullpath, identity.UID, identity.GID) 46 }) 47 } 48 49 // normalizeDest normalises the destination of a COPY/ADD command in a 50 // platform semantically consistent way. 51 func normalizeDest(workingDir, requested string) (string, error) { 52 dest := filepath.FromSlash(requested) 53 endsInSlash := strings.HasSuffix(dest, string(os.PathSeparator)) 54 55 if !path.IsAbs(requested) { 56 dest = path.Join("/", filepath.ToSlash(workingDir), dest) 57 // Make sure we preserve any trailing slash 58 if endsInSlash { 59 dest += "/" 60 } 61 } 62 return dest, nil 63 } 64 65 func containsWildcards(name string) bool { 66 for i := 0; i < len(name); i++ { 67 ch := name[i] 68 if ch == '\\' { 69 i++ 70 } else if ch == '*' || ch == '?' || ch == '[' { 71 return true 72 } 73 } 74 return false 75 } 76 77 func validateCopySourcePath(imageSource *imageMount, origPath string) error { 78 return nil 79 }