file_entry.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 // Inode
  9. File *File // Remote file information
  10. Name string // local name
  11. Attr fuseops.InodeAttributes // Cached attributes
  12. tempFile *fileWrapper // Cached file
  13. }
  14. // SetFile update attributes and set drive.File
  15. func (fe *FileEntry) SetFile(file *File, uid, gid uint32) { // Should remove from here maybe?
  16. fe.File = file
  17. fe.Attr = fuseops.InodeAttributes{
  18. Size: fe.File.Size,
  19. Crtime: file.CreatedTime,
  20. Ctime: file.CreatedTime,
  21. Mtime: file.ModifiedTime,
  22. Atime: file.AccessedTime,
  23. Mode: file.Mode,
  24. Uid: uid,
  25. Gid: gid,
  26. }
  27. }
  28. // IsDir returns true if entry is a directory:w
  29. func (fe *FileEntry) IsDir() bool {
  30. return fe.Attr.Mode&os.ModeDir == os.ModeDir
  31. }
  32. // HasParentID check parent by cloud ID
  33. func (fe *FileEntry) HasParentID(parentID string) bool {
  34. // Exceptional case
  35. if fe.Inode == fuseops.RootInodeID {
  36. return false
  37. }
  38. if parentID == "" {
  39. if fe.File == nil || len(fe.File.Parents) == 0 { // We are looking in root
  40. return true
  41. }
  42. return false
  43. }
  44. if fe.File == nil { // Case gid is not empty and GFile is null
  45. return false
  46. }
  47. for _, pgid := range fe.File.Parents {
  48. if pgid == parentID {
  49. return true
  50. }
  51. }
  52. return false
  53. }
  54. // HasParent check Parent by entry
  55. func (fe *FileEntry) HasParent(parent *FileEntry) bool {
  56. // Exceptional case
  57. if fe.Inode == fuseops.RootInodeID {
  58. return false
  59. }
  60. if parent.File == nil {
  61. return fe.HasParentID("")
  62. }
  63. return fe.HasParentID(parent.File.ID)
  64. }