copy_unix.go 1.4 KB

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