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