copy_windows.go 1016 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package dockerfile
  2. import (
  3. "errors"
  4. "path/filepath"
  5. "strings"
  6. "github.com/docker/docker/pkg/idtools"
  7. )
  8. var pathBlacklist = map[string]bool{
  9. "c:\\": true,
  10. "c:\\windows": true,
  11. }
  12. func fixPermissions(source, destination string, rootIDs idtools.IDPair, overrideSkip bool) error {
  13. // chown is not supported on Windows
  14. return nil
  15. }
  16. func validateCopySourcePath(imageSource *imageMount, origPath, platform string) error {
  17. // validate windows paths from other images + LCOW
  18. if imageSource == nil || platform != "windows" {
  19. return nil
  20. }
  21. origPath = filepath.FromSlash(origPath)
  22. p := strings.ToLower(filepath.Clean(origPath))
  23. if !filepath.IsAbs(p) {
  24. if filepath.VolumeName(p) != "" {
  25. if p[len(p)-2:] == ":." { // case where clean returns weird c:. paths
  26. p = p[:len(p)-1]
  27. }
  28. p += "\\"
  29. } else {
  30. p = filepath.Join("c:\\", p)
  31. }
  32. }
  33. if _, blacklisted := pathBlacklist[p]; blacklisted {
  34. return errors.New("copy from c:\\ or c:\\windows is not allowed on windows")
  35. }
  36. return nil
  37. }