file_entry.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package basefs
  2. import (
  3. "os"
  4. "github.com/jacobsa/fuse/fuseops"
  5. )
  6. //FileEntry entry to handle files
  7. type FileEntry struct {
  8. //Inode fuseops.InodeID
  9. GID string // google driveID
  10. File File
  11. Name string // local name
  12. Attr fuseops.InodeAttributes // Cached attributes
  13. tempFile *os.File // Cached file
  14. }
  15. // Why?
  16. func (fe *FileEntry) HasParent(parent *FileEntry) bool {
  17. // Exceptional case
  18. /*if fe.Inode == fuseops.RootInodeID {
  19. return false
  20. }*/
  21. if parent.GID == "" && fe.File == nil && len(fe.File.Parents()) == 0 { // We are looking in root
  22. return true
  23. }
  24. if fe.File == nil { // Case gid is not empty and GFile is nil
  25. return false
  26. }
  27. for _, pgid := range fe.File.Parents() {
  28. if pgid == parent.GID {
  29. return true
  30. }
  31. }
  32. return false
  33. }
  34. func (fe *FileEntry) HasParentGID(parentGID string) bool {
  35. // Exceptional case
  36. /*if fe.Inode == fuseops.RootInodeID {
  37. return false
  38. }*/
  39. if parentGID == "" && fe.File == nil && len(fe.File.Parents()) == 0 { // We are looking in root
  40. return true
  41. }
  42. if fe.File == nil { // Case gid is not empty and GFile is null
  43. return false
  44. }
  45. for _, pgid := range fe.File.Parents() {
  46. if pgid == parentGID {
  47. return true
  48. }
  49. }
  50. return false
  51. }
  52. // SetGFile update attributes and set drive.File
  53. func (fe *FileEntry) SetFile(file File, uid, gid uint32) { // Should remove from here maybe?
  54. fe.File = file
  55. // GetAttribute from GFile somehow
  56. // Create Attribute
  57. fe.Attr = file.Attr()
  58. //fe.Attr.Uid = fe.container.uid
  59. //fe.Attr.Gid = fe.container.gid
  60. }
  61. // Sync cached , upload to gdrive
  62. // IsDir returns true if entry is a directory:w
  63. func (fe *FileEntry) IsDir() bool {
  64. return fe.Attr.Mode&os.ModeDir == os.ModeDir
  65. }