github.com/ncw/rclone@v1.48.1-0.20190724201158-a35aa1360e3e/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 } 16 17 // NewDir creates an unspecialized Directory object 18 func NewDir(remote string, modTime time.Time) *Dir { 19 return &Dir{ 20 remote: remote, 21 modTime: modTime, 22 size: -1, 23 items: -1, 24 } 25 } 26 27 // NewDirCopy creates an unspecialized copy of the Directory object passed in 28 func NewDirCopy(ctx context.Context, d Directory) *Dir { 29 return &Dir{ 30 remote: d.Remote(), 31 modTime: d.ModTime(ctx), 32 size: d.Size(), 33 items: d.Items(), 34 id: d.ID(), 35 } 36 } 37 38 // String returns the name 39 func (d *Dir) String() string { 40 return d.remote 41 } 42 43 // Remote returns the remote path 44 func (d *Dir) Remote() string { 45 return d.remote 46 } 47 48 // SetRemote sets the remote 49 func (d *Dir) SetRemote(remote string) *Dir { 50 d.remote = remote 51 return d 52 } 53 54 // ID gets the optional ID 55 func (d *Dir) ID() string { 56 return d.id 57 } 58 59 // SetID sets the optional ID 60 func (d *Dir) SetID(id string) *Dir { 61 d.id = id 62 return d 63 } 64 65 // ModTime returns the modification date of the file 66 // It should return a best guess if one isn't available 67 func (d *Dir) ModTime(ctx context.Context) time.Time { 68 if !d.modTime.IsZero() { 69 return d.modTime 70 } 71 return time.Now() 72 } 73 74 // Size returns the size of the file 75 func (d *Dir) Size() int64 { 76 return d.size 77 } 78 79 // SetSize sets the size of the directory 80 func (d *Dir) SetSize(size int64) *Dir { 81 d.size = size 82 return d 83 } 84 85 // Items returns the count of items in this directory or this 86 // directory and subdirectories if known, -1 for unknown 87 func (d *Dir) Items() int64 { 88 return d.items 89 } 90 91 // SetItems sets the number of items in the directory 92 func (d *Dir) SetItems(items int64) *Dir { 93 d.items = items 94 return d 95 } 96 97 // Check interfaces 98 var ( 99 _ DirEntry = (*Dir)(nil) 100 _ Directory = (*Dir)(nil) 101 )