copy_unix.go 1.3 KB

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