sharefs.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package sharefs
  2. import (
  3. "errors"
  4. "io"
  5. "os"
  6. "path/filepath"
  7. "strings"
  8. "time"
  9. "imuslab.com/arozos/mod/filesystem/fserror"
  10. )
  11. /*
  12. filesystemAbstraction.go
  13. This file contains all the abstraction funtion of a local file system.
  14. */
  15. type ShareFileSystemAbstraction struct {
  16. UUID string
  17. ShareUUIDToVpathResolver func(string) (string, error)
  18. }
  19. func NewShareFileSystemAbstraction(uuid string, resolverFunction func(string) (string, error)) ShareFileSystemAbstraction {
  20. return ShareFileSystemAbstraction{
  21. UUID: uuid,
  22. ShareUUIDToVpathResolver: resolverFunction,
  23. }
  24. }
  25. func (l ShareFileSystemAbstraction) Chmod(filename string, mode os.FileMode) error {
  26. return nil
  27. }
  28. func (l ShareFileSystemAbstraction) Chown(filename string, uid int, gid int) error {
  29. return nil
  30. }
  31. func (l ShareFileSystemAbstraction) Chtimes(filename string, atime time.Time, mtime time.Time) error {
  32. return nil
  33. }
  34. func (l ShareFileSystemAbstraction) Create(filename string) (*os.File, error) {
  35. return nil, nil
  36. }
  37. func (l ShareFileSystemAbstraction) Mkdir(filename string, mode os.FileMode) error {
  38. return nil
  39. }
  40. func (l ShareFileSystemAbstraction) MkdirAll(filename string, mode os.FileMode) error {
  41. return nil
  42. }
  43. func (l ShareFileSystemAbstraction) Name() string {
  44. return ""
  45. }
  46. func (l ShareFileSystemAbstraction) Open(filename string) (*os.File, error) {
  47. return nil, nil
  48. }
  49. func (l ShareFileSystemAbstraction) OpenFile(filename string, flag int, perm os.FileMode) (*os.File, error) {
  50. return nil, nil
  51. }
  52. func (l ShareFileSystemAbstraction) Remove(filename string) error {
  53. return nil
  54. }
  55. func (l ShareFileSystemAbstraction) RemoveAll(path string) error {
  56. return nil
  57. }
  58. func (l ShareFileSystemAbstraction) Rename(oldname, newname string) error {
  59. return nil
  60. }
  61. func (l ShareFileSystemAbstraction) Stat(filename string) (os.FileInfo, error) {
  62. return nil, nil
  63. }
  64. /*
  65. Abstraction Utilities
  66. */
  67. func (l ShareFileSystemAbstraction) VirtualPathToRealPath(subpath string, username string) (string, error) {
  68. subpath = filepath.ToSlash(filepath.Clean(subpath))
  69. if strings.HasPrefix(subpath, l.UUID+":") {
  70. subpath = strings.TrimPrefix(subpath, l.UUID+":")
  71. }
  72. subpath = subpath[1:] //Trim off the first / from the subpath
  73. uuid := subpath
  74. if strings.Contains(subpath, "/") {
  75. uuid = strings.Split(subpath, "/")[0]
  76. }
  77. redirectVpath, err := l.ShareUUIDToVpathResolver(uuid)
  78. if err != nil {
  79. return "", err
  80. }
  81. return "", fserror.NewRedirectionError(redirectVpath)
  82. }
  83. func (l ShareFileSystemAbstraction) RealPathToVirtualPath(fullpath string, username string) (string, error) {
  84. return "", errors.New("SHAREFS WORK IN PROGRESS")
  85. }
  86. func (l ShareFileSystemAbstraction) FileExists(realpath string) bool {
  87. return false
  88. }
  89. func (l ShareFileSystemAbstraction) IsDir(realpath string) bool {
  90. return false
  91. }
  92. func (l ShareFileSystemAbstraction) Glob(realpathWildcard string) ([]string, error) {
  93. return []string{}, nil
  94. }
  95. func (l ShareFileSystemAbstraction) GetFileSize(realpath string) int64 {
  96. return 0
  97. }
  98. func (l ShareFileSystemAbstraction) GetModTime(realpath string) (int64, error) {
  99. return 0, fserror.ErrNullOperation
  100. }
  101. func (l ShareFileSystemAbstraction) WriteFile(filename string, content []byte, mode os.FileMode) error {
  102. return nil
  103. }
  104. func (l ShareFileSystemAbstraction) ReadFile(filename string) ([]byte, error) {
  105. return []byte(""), fserror.ErrNullOperation
  106. }
  107. func (l ShareFileSystemAbstraction) WriteStream(filename string, stream io.Reader, mode os.FileMode) error {
  108. return fserror.ErrOperationNotSupported
  109. }
  110. func (l ShareFileSystemAbstraction) ReadStream(filename string) (io.ReadCloser, error) {
  111. return nil, fserror.ErrOperationNotSupported
  112. }
  113. func (l ShareFileSystemAbstraction) Walk(root string, walkFn filepath.WalkFunc) error {
  114. return fserror.ErrOperationNotSupported
  115. }