fs: add optional ID to fs.Directory and set it in the remotes which care

This commit is contained in:
Nick Craig-Wood 2017-08-02 16:44:36 +01:00
parent 74687c25f5
commit 81a2ab599f
6 changed files with 20 additions and 4 deletions

View File

@ -427,7 +427,7 @@ func (f *Fs) List(dir string) (entries fs.DirEntries, err error) {
// cache the directory ID for later lookups
f.dirCache.Put(remote, *node.Id)
when, _ := time.Parse(timeFormat, *node.ModifiedDate) // FIXME
d := fs.NewDir(remote, when)
d := fs.NewDir(remote, when).SetID(*node.Id)
entries = append(entries, d)
case fileKind:
o, err := f.newObjectWithInfo(remote, node)

View File

@ -454,7 +454,7 @@ func (f *Fs) List(dir string) (entries fs.DirEntries, err error) {
if info.Type == api.ItemTypeFolder {
// cache the directory ID for later lookups
f.dirCache.Put(remote, info.ID)
d := fs.NewDir(remote, info.ModTime())
d := fs.NewDir(remote, info.ModTime()).SetID(info.ID)
// FIXME more info from dir?
entries = append(entries, d)
} else if info.Type == api.ItemTypeFile {

View File

@ -591,7 +591,7 @@ func (f *Fs) List(dir string) (entries fs.DirEntries, err error) {
// cache the directory ID for later lookups
f.dirCache.Put(remote, item.Id)
when, _ := time.Parse(timeFormatIn, item.ModifiedDate)
d := fs.NewDir(remote, when)
d := fs.NewDir(remote, when).SetID(item.Id)
entries = append(entries, d)
case item.Md5Checksum != "" || item.FileSize > 0:
// If item has MD5 sum or a length it is a file stored on drive

View File

@ -8,6 +8,7 @@ type Dir struct {
modTime time.Time // modification or creation time - IsZero for unknown
size int64 // size of directory and contents or -1 if unknown
items int64 // number of objects or -1 for unknown
id string // optional ID
}
// NewDir creates an unspecialized Directory object
@ -46,6 +47,17 @@ func (d *Dir) SetRemote(remote string) *Dir {
return d
}
// ID gets the optional ID
func (d *Dir) ID() string {
return d.id
}
// SetID sets the optional ID
func (d *Dir) SetID(id string) *Dir {
d.id = id
return d
}
// ModTime returns the modification date of the file
// It should return a best guess if one isn't available
func (d *Dir) ModTime() time.Time {

View File

@ -219,6 +219,10 @@ type Directory interface {
// Items returns the count of items in this directory or this
// directory and subdirectories if known, -1 for unknown
Items() int64
// ID returns the internal ID of this directory if known, or
// "" otherwise
ID() string
}
// MimeTyper is an optional interface for Object

View File

@ -423,7 +423,7 @@ func (f *Fs) List(dir string) (entries fs.DirEntries, err error) {
if info.Folder != nil {
// cache the directory ID for later lookups
f.dirCache.Put(remote, info.ID)
d := fs.NewDir(remote, time.Time(info.LastModifiedDateTime))
d := fs.NewDir(remote, time.Time(info.LastModifiedDateTime)).SetID(info.ID)
if info.Folder != nil {
d.SetItems(info.Folder.ChildCount)
}