github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/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/idtools" 13 ) 14 15 func fixPermissions(source, destination string, identity idtools.Identity, overrideSkip bool) error { 16 var ( 17 skipChownRoot bool 18 err error 19 ) 20 if !overrideSkip { 21 skipChownRoot, err = isExistingDirectory(destination) 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.WalkDir(source, func(fullpath string, _ os.DirEntry, _ 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 // normalizeDest normalises the destination of a COPY/ADD command in a 48 // platform semantically consistent way. 49 func normalizeDest(workingDir, requested string) (string, error) { 50 dest := filepath.FromSlash(requested) 51 endsInSlash := strings.HasSuffix(dest, string(os.PathSeparator)) 52 53 if !path.IsAbs(requested) { 54 dest = path.Join("/", filepath.ToSlash(workingDir), dest) 55 // Make sure we preserve any trailing slash 56 if endsInSlash { 57 dest += "/" 58 } 59 } 60 return dest, nil 61 } 62 63 func containsWildcards(name string) bool { 64 for i := 0; i < len(name); i++ { 65 ch := name[i] 66 if ch == '\\' { 67 i++ 68 } else if ch == '*' || ch == '?' || ch == '[' { 69 return true 70 } 71 } 72 return false 73 } 74 75 func validateCopySourcePath(imageSource *imageMount, origPath string) error { 76 return nil 77 }