symlink.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright © 2018 Steve Francia <spf@spf13.com>.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. package afero
  14. import (
  15. "errors"
  16. )
  17. // Symlinker is an optional interface in Afero. It is only implemented by the
  18. // filesystems saying so.
  19. // It indicates support for 3 symlink related interfaces that implement the
  20. // behaviors of the os methods:
  21. // - Lstat
  22. // - Symlink, and
  23. // - Readlink
  24. type Symlinker interface {
  25. Lstater
  26. Linker
  27. LinkReader
  28. }
  29. // Linker is an optional interface in Afero. It is only implemented by the
  30. // filesystems saying so.
  31. // It will call Symlink if the filesystem itself is, or it delegates to, the os filesystem,
  32. // or the filesystem otherwise supports Symlink's.
  33. type Linker interface {
  34. SymlinkIfPossible(oldname, newname string) error
  35. }
  36. // ErrNoSymlink is the error that will be wrapped in an os.LinkError if a file system
  37. // does not support Symlink's either directly or through its delegated filesystem.
  38. // As expressed by support for the Linker interface.
  39. var ErrNoSymlink = errors.New("symlink not supported")
  40. // LinkReader is an optional interface in Afero. It is only implemented by the
  41. // filesystems saying so.
  42. type LinkReader interface {
  43. ReadlinkIfPossible(name string) (string, error)
  44. }
  45. // ErrNoReadlink is the error that will be wrapped in an os.Path if a file system
  46. // does not support the readlink operation either directly or through its delegated filesystem.
  47. // As expressed by support for the LinkReader interface.
  48. var ErrNoReadlink = errors.New("readlink not supported")