github.com/divyam234/rclone@v1.64.1/fs/dir.go (about) 1 package fs 2 3 import ( 4 "context" 5 "time" 6 ) 7 8 // Dir describes an unspecialized directory for directory/container/bucket lists 9 type Dir struct { 10 remote string // name of the directory 11 modTime time.Time // modification or creation time - IsZero for unknown 12 size int64 // size of directory and contents or -1 if unknown 13 items int64 // number of objects or -1 for unknown 14 id string // optional ID 15 parent string // optional parent directory ID 16 } 17 18 // NewDir creates an unspecialized Directory object 19 // 20 // If the modTime is unknown pass in time.Time{} 21 func NewDir(remote string, modTime time.Time) *Dir { 22 return &Dir{ 23 remote: remote, 24 modTime: modTime, 25 size: -1, 26 items: -1, 27 } 28 } 29 30 // NewDirCopy creates an unspecialized copy of the Directory object passed in 31 func NewDirCopy(ctx context.Context, d Directory) *Dir { 32 return &Dir{ 33 remote: d.Remote(), 34 modTime: d.ModTime(ctx), 35 size: d.Size(), 36 items: d.Items(), 37 id: d.ID(), 38 } 39 } 40 41 // String returns the name 42 func (d *Dir) String() string { 43 return d.remote 44 } 45 46 // Remote returns the remote path 47 func (d *Dir) Remote() string { 48 return d.remote 49 } 50 51 // SetRemote sets the remote 52 func (d *Dir) SetRemote(remote string) *Dir { 53 d.remote = remote 54 return d 55 } 56 57 // ID gets the optional ID 58 func (d *Dir) ID() string { 59 return d.id 60 } 61 62 // SetID sets the optional ID 63 func (d *Dir) SetID(id string) *Dir { 64 d.id = id 65 return d 66 } 67 68 // ParentID returns the IDs of the Dir parent if known 69 func (d *Dir) ParentID() string { 70 return d.parent 71 } 72 73 // SetParentID sets the optional parent ID of the Dir 74 func (d *Dir) SetParentID(parent string) *Dir { 75 d.parent = parent 76 return d 77 } 78 79 // ModTime returns the modification date of the file 80 // 81 // If one isn't available it returns the configured --default-dir-time 82 func (d *Dir) ModTime(ctx context.Context) time.Time { 83 if !d.modTime.IsZero() { 84 return d.modTime 85 } 86 ci := GetConfig(ctx) 87 return time.Time(ci.DefaultTime) 88 } 89 90 // Size returns the size of the file 91 func (d *Dir) Size() int64 { 92 return d.size 93 } 94 95 // SetSize sets the size of the directory 96 func (d *Dir) SetSize(size int64) *Dir { 97 d.size = size 98 return d 99 } 100 101 // Items returns the count of items in this directory or this 102 // directory and subdirectories if known, -1 for unknown 103 func (d *Dir) Items() int64 { 104 return d.items 105 } 106 107 // SetItems sets the number of items in the directory 108 func (d *Dir) SetItems(items int64) *Dir { 109 d.items = items 110 return d 111 } 112 113 // Check interfaces 114 var ( 115 _ DirEntry = (*Dir)(nil) 116 _ Directory = (*Dir)(nil) 117 )