internals_unix.go 670 B

1234567891011121314151617181920212223242526
  1. // +build !windows
  2. package dockerfile
  3. import (
  4. "os"
  5. "path/filepath"
  6. "strings"
  7. "github.com/docker/docker/pkg/system"
  8. )
  9. // normaliseDest normalises the destination of a COPY/ADD command in a
  10. // platform semantically consistent way.
  11. func normaliseDest(cmdName, workingDir, requested string) (string, error) {
  12. dest := filepath.FromSlash(requested)
  13. endsInSlash := strings.HasSuffix(requested, string(os.PathSeparator))
  14. if !system.IsAbs(requested) {
  15. dest = filepath.Join(string(os.PathSeparator), filepath.FromSlash(workingDir), dest)
  16. // Make sure we preserve any trailing slash
  17. if endsInSlash {
  18. dest += string(os.PathSeparator)
  19. }
  20. }
  21. return dest, nil
  22. }