errors.go 975 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package safepath
  2. // ErrNotAccessible is returned by Join when the resulting path doesn't exist,
  3. // is not accessible, or any of the path components was replaced with a symlink
  4. // during the path traversal.
  5. type ErrNotAccessible struct {
  6. Path string
  7. Cause error
  8. }
  9. func (*ErrNotAccessible) NotFound() {}
  10. func (e *ErrNotAccessible) Unwrap() error {
  11. return e.Cause
  12. }
  13. func (e *ErrNotAccessible) Error() string {
  14. msg := "cannot access path " + e.Path
  15. if e.Cause != nil {
  16. msg += ": " + e.Cause.Error()
  17. }
  18. return msg
  19. }
  20. // ErrEscapesBase is returned by Join when the resulting concatenation would
  21. // point outside of the specified base directory.
  22. type ErrEscapesBase struct {
  23. Base, Subpath string
  24. }
  25. func (*ErrEscapesBase) InvalidParameter() {}
  26. func (e *ErrEscapesBase) Error() string {
  27. msg := "path concatenation escapes the base directory"
  28. if e.Base != "" {
  29. msg += ", base: " + e.Base
  30. }
  31. if e.Subpath != "" {
  32. msg += ", subpath: " + e.Subpath
  33. }
  34. return msg
  35. }