github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/builder/dockerfile/copy_unix.go (about) 1 //go:build !windows 2 3 package dockerfile // import "github.com/Prakhar-Agarwal-byte/moby/builder/dockerfile" 4 5 import ( 6 "os" 7 "path" 8 "path/filepath" 9 "strings" 10 11 "github.com/Prakhar-Agarwal-byte/moby/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 skipChownRoot, err = isExistingDirectory(destination) 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.WalkDir(source, func(fullpath string, _ os.DirEntry, _ 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 // normalizeDest normalises the destination of a COPY/ADD command in a 47 // platform semantically consistent way. 48 func normalizeDest(workingDir, requested string) (string, error) { 49 dest := filepath.FromSlash(requested) 50 endsInSlash := strings.HasSuffix(dest, string(os.PathSeparator)) 51 52 if !path.IsAbs(requested) { 53 dest = path.Join("/", filepath.ToSlash(workingDir), dest) 54 // Make sure we preserve any trailing slash 55 if endsInSlash { 56 dest += "/" 57 } 58 } 59 return dest, nil 60 } 61 62 func containsWildcards(name string) bool { 63 for i := 0; i < len(name); i++ { 64 ch := name[i] 65 if ch == '\\' { 66 i++ 67 } else if ch == '*' || ch == '?' || ch == '[' { 68 return true 69 } 70 } 71 return false 72 } 73 74 func validateCopySourcePath(imageSource *imageMount, origPath string) error { 75 return nil 76 }