nfsfs.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package nfsfs
  2. import (
  3. "io"
  4. "io/fs"
  5. "os"
  6. "path/filepath"
  7. "strings"
  8. "time"
  9. "imuslab.com/arozos/mod/filesystem/arozfs"
  10. )
  11. /*
  12. FTPFS.go
  13. File System Abstraciton for File Transfer Protocol (FTP)
  14. */
  15. type NFSFileSystemAbstraction struct {
  16. uuid string
  17. hierarchy string
  18. }
  19. func NewNFSFileSystemAbstraction(uuid string, hierarchy string, ipAndPort string, username string, password string) (NFSFileSystemAbstraction, error) {
  20. return NFSFileSystemAbstraction{
  21. uuid: uuid,
  22. hierarchy: hierarchy,
  23. }, nil
  24. }
  25. func (l NFSFileSystemAbstraction) Chmod(filename string, mode os.FileMode) error {
  26. return arozfs.ErrNullOperation
  27. }
  28. func (l NFSFileSystemAbstraction) Chown(filename string, uid int, gid int) error {
  29. return arozfs.ErrNullOperation
  30. }
  31. func (l NFSFileSystemAbstraction) Chtimes(filename string, atime time.Time, mtime time.Time) error {
  32. return arozfs.ErrNullOperation
  33. }
  34. func (l NFSFileSystemAbstraction) Create(filename string) (arozfs.File, error) {
  35. return nil, arozfs.ErrNullOperation
  36. }
  37. func (l NFSFileSystemAbstraction) Mkdir(filename string, mode os.FileMode) error {
  38. return arozfs.ErrNullOperation
  39. }
  40. func (l NFSFileSystemAbstraction) MkdirAll(filename string, mode os.FileMode) error {
  41. return arozfs.ErrNullOperation
  42. }
  43. func (l NFSFileSystemAbstraction) Name() string {
  44. return ""
  45. }
  46. func (l NFSFileSystemAbstraction) Open(filename string) (arozfs.File, error) {
  47. return nil, arozfs.ErrNullOperation
  48. }
  49. func (l NFSFileSystemAbstraction) OpenFile(filename string, flag int, perm os.FileMode) (arozfs.File, error) {
  50. return nil, arozfs.ErrNullOperation
  51. }
  52. func (l NFSFileSystemAbstraction) Remove(filename string) error {
  53. return arozfs.ErrNullOperation
  54. }
  55. func (l NFSFileSystemAbstraction) RemoveAll(path string) error {
  56. return arozfs.ErrNullOperation
  57. }
  58. func (l NFSFileSystemAbstraction) Rename(oldname, newname string) error {
  59. return arozfs.ErrNullOperation
  60. }
  61. func (l NFSFileSystemAbstraction) Stat(filename string) (os.FileInfo, error) {
  62. return nil, arozfs.ErrNullOperation
  63. }
  64. func (l NFSFileSystemAbstraction) Close() error {
  65. return nil
  66. }
  67. /*
  68. Abstraction Utilities
  69. */
  70. func (a NFSFileSystemAbstraction) VirtualPathToRealPath(subpath string, username string) (string, error) {
  71. return arozfs.GenericVirtualPathToRealPathTranslator(a.uuid, a.hierarchy, subpath, username)
  72. }
  73. func (a NFSFileSystemAbstraction) RealPathToVirtualPath(fullpath string, username string) (string, error) {
  74. return arozfs.GenericRealPathToVirtualPathTranslator(a.uuid, a.hierarchy, fullpath, username)
  75. }
  76. func (a NFSFileSystemAbstraction) FileExists(realpath string) bool {
  77. return false
  78. }
  79. func (a NFSFileSystemAbstraction) IsDir(realpath string) bool {
  80. return false
  81. }
  82. func (a NFSFileSystemAbstraction) Glob(realpathWildcard string) ([]string, error) {
  83. return []string{}, arozfs.ErrNullOperation
  84. }
  85. func (a NFSFileSystemAbstraction) GetFileSize(realpath string) int64 {
  86. return 0
  87. }
  88. func (a NFSFileSystemAbstraction) GetModTime(realpath string) (int64, error) {
  89. return 0, arozfs.ErrOperationNotSupported
  90. }
  91. func (a NFSFileSystemAbstraction) WriteFile(filename string, content []byte, mode os.FileMode) error {
  92. return arozfs.ErrNullOperation
  93. }
  94. func (a NFSFileSystemAbstraction) ReadFile(filename string) ([]byte, error) {
  95. return []byte(""), arozfs.ErrOperationNotSupported
  96. }
  97. func (a NFSFileSystemAbstraction) ReadDir(filename string) ([]fs.DirEntry, error) {
  98. return []fs.DirEntry{}, arozfs.ErrOperationNotSupported
  99. }
  100. func (a NFSFileSystemAbstraction) WriteStream(filename string, stream io.Reader, mode os.FileMode) error {
  101. return arozfs.ErrNullOperation
  102. }
  103. func (a NFSFileSystemAbstraction) ReadStream(filename string) (io.ReadCloser, error) {
  104. return nil, arozfs.ErrOperationNotSupported
  105. }
  106. func (a NFSFileSystemAbstraction) Walk(root string, walkFn filepath.WalkFunc) error {
  107. return arozfs.ErrOperationNotSupported
  108. }
  109. //Utilities
  110. func filterFilepath(rawpath string) string {
  111. rawpath = arozfs.ToSlash(filepath.Clean(strings.TrimSpace(rawpath)))
  112. if strings.HasPrefix(rawpath, "./") {
  113. return rawpath[1:]
  114. } else if rawpath == "." || rawpath == "" {
  115. return "/"
  116. }
  117. return rawpath
  118. }