ftpFileWrapper.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package ftpfs
  2. import (
  3. "io/fs"
  4. "time"
  5. "github.com/jlaffaye/ftp"
  6. )
  7. type File struct {
  8. entry ftp.Entry
  9. }
  10. /*
  11. func NewFTPFsFile(wrappingFile *smb2.File) *File {
  12. return &smbfsFile{
  13. file: wrappingFile,
  14. }
  15. }
  16. func (f *File) Chdir() error {
  17. return arozfs.ErrOperationNotSupported
  18. }
  19. func (f *File) Chmod(mode os.FileMode) error {
  20. return arozfs.ErrOperationNotSupported
  21. }
  22. func (f *File) Chown(uid, gid int) error {
  23. return arozfs.ErrOperationNotSupported
  24. }
  25. func (f *File) Close() error {
  26. return f.file.Close()
  27. }
  28. func (f *File) Name() string {
  29. return f.file.Name()
  30. }
  31. func (f *File) Read(b []byte) (n int, err error) {
  32. return f.file.Read(b)
  33. }
  34. func (f *File) ReadAt(b []byte, off int64) (n int, err error) {
  35. return f.file.ReadAt(b, off)
  36. }
  37. func (f *File) ReadDir(n int) ([]fs.DirEntry, error) {
  38. return []fs.DirEntry{}, arozfs.ErrOperationNotSupported
  39. }
  40. func (f *File) Readdirnames(n int) (names []string, err error) {
  41. fi, err := f.file.Readdir(n)
  42. if err != nil {
  43. return []string{}, err
  44. }
  45. names = []string{}
  46. for _, i := range fi {
  47. names = append(names, i.Name())
  48. }
  49. return names, nil
  50. }
  51. func (f *File) ReadFrom(r io.Reader) (n int64, err error) {
  52. return f.file.ReadFrom(r)
  53. }
  54. func (f *File) Readdir(n int) ([]fs.FileInfo, error) {
  55. return f.file.Readdir(n)
  56. }
  57. func (f *File) Seek(offset int64, whence int) (ret int64, err error) {
  58. return f.file.Seek(offset, whence)
  59. }
  60. func (f *File) Stat() (fs.FileInfo, error) {
  61. return f.file.Stat()
  62. }
  63. func (f *File) Sync() error {
  64. return f.file.Sync()
  65. }
  66. func (f *File) Truncate(size int64) error {
  67. return f.file.Truncate(size)
  68. }
  69. func (f *File) Write(b []byte) (n int, err error) {
  70. return f.file.Write(b)
  71. }
  72. func (f *File) WriteAt(b []byte, off int64) (n int, err error) {
  73. return f.file.WriteAt(b, off)
  74. }
  75. func (f *File) WriteString(s string) (n int, err error) {
  76. return f.file.WriteString(s)
  77. }
  78. */
  79. type DirEntry struct {
  80. finfo *ftp.Entry
  81. conn *ftp.ServerConn
  82. path string
  83. }
  84. func newDirEntryFromFTPEntry(targetEntry *ftp.Entry, conn *ftp.ServerConn, originalPath string) *DirEntry {
  85. return &DirEntry{
  86. finfo: targetEntry,
  87. conn: conn,
  88. }
  89. }
  90. func (de DirEntry) Name() string {
  91. return de.finfo.Name
  92. }
  93. func (de DirEntry) IsDir() bool {
  94. return de.finfo.Type == ftp.EntryTypeFolder
  95. }
  96. func (de DirEntry) Type() fs.FileMode {
  97. return 0777
  98. }
  99. func (de DirEntry) Info() (fs.FileInfo, error) {
  100. e := NewFileInfoFromEntry(de.finfo, de.conn, de.path)
  101. return e, nil
  102. }
  103. type FileInfo struct {
  104. entry *ftp.Entry
  105. conn *ftp.ServerConn
  106. path string
  107. }
  108. func NewFileInfoFromEntry(e *ftp.Entry, c *ftp.ServerConn, originalPath string) FileInfo {
  109. return FileInfo{
  110. entry: e,
  111. conn: c,
  112. path: originalPath,
  113. }
  114. }
  115. func (fi FileInfo) Name() string {
  116. return fi.entry.Name
  117. }
  118. func (fi FileInfo) Size() int64 {
  119. return int64(fi.entry.Size)
  120. }
  121. func (fi FileInfo) Mode() fs.FileMode {
  122. return 664
  123. }
  124. func (fi FileInfo) ModTime() time.Time {
  125. return fi.entry.Time
  126. }
  127. func (fi FileInfo) IsDir() bool {
  128. return fi.entry.Type == ftp.EntryTypeFolder
  129. }
  130. func (fi FileInfo) Sys() interface{} {
  131. return nil
  132. }