本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.6KB

  1. package afero
  2. import (
  3. "os"
  4. "syscall"
  5. "time"
  6. )
  7. var _ Lstater = (*ReadOnlyFs)(nil)
  8. type ReadOnlyFs struct {
  9. source Fs
  10. }
  11. func NewReadOnlyFs(source Fs) Fs {
  12. return &ReadOnlyFs{source: source}
  13. }
  14. func (r *ReadOnlyFs) ReadDir(name string) ([]os.FileInfo, error) {
  15. return ReadDir(r.source, name)
  16. }
  17. func (r *ReadOnlyFs) Chtimes(n string, a, m time.Time) error {
  18. return syscall.EPERM
  19. }
  20. func (r *ReadOnlyFs) Chmod(n string, m os.FileMode) error {
  21. return syscall.EPERM
  22. }
  23. func (r *ReadOnlyFs) Name() string {
  24. return "ReadOnlyFilter"
  25. }
  26. func (r *ReadOnlyFs) Stat(name string) (os.FileInfo, error) {
  27. return r.source.Stat(name)
  28. }
  29. func (r *ReadOnlyFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
  30. if lsf, ok := r.source.(Lstater); ok {
  31. return lsf.LstatIfPossible(name)
  32. }
  33. fi, err := r.Stat(name)
  34. return fi, false, err
  35. }
  36. func (r *ReadOnlyFs) Rename(o, n string) error {
  37. return syscall.EPERM
  38. }
  39. func (r *ReadOnlyFs) RemoveAll(p string) error {
  40. return syscall.EPERM
  41. }
  42. func (r *ReadOnlyFs) Remove(n string) error {
  43. return syscall.EPERM
  44. }
  45. func (r *ReadOnlyFs) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
  46. if flag&(os.O_WRONLY|syscall.O_RDWR|os.O_APPEND|os.O_CREATE|os.O_TRUNC) != 0 {
  47. return nil, syscall.EPERM
  48. }
  49. return r.source.OpenFile(name, flag, perm)
  50. }
  51. func (r *ReadOnlyFs) Open(n string) (File, error) {
  52. return r.source.Open(n)
  53. }
  54. func (r *ReadOnlyFs) Mkdir(n string, p os.FileMode) error {
  55. return syscall.EPERM
  56. }
  57. func (r *ReadOnlyFs) MkdirAll(n string, p os.FileMode) error {
  58. return syscall.EPERM
  59. }
  60. func (r *ReadOnlyFs) Create(n string) (File, error) {
  61. return nil, syscall.EPERM
  62. }
上海开阖软件有限公司 沪ICP备12045867号-1