mirror of
https://github.com/rclone/rclone.git
synced 2025-01-22 14:19:56 +01:00
fs: add optional ID to fs.Directory and set it in the remotes which care
This commit is contained in:
parent
74687c25f5
commit
81a2ab599f
@ -427,7 +427,7 @@ func (f *Fs) List(dir string) (entries fs.DirEntries, err error) {
|
|||||||
// cache the directory ID for later lookups
|
// cache the directory ID for later lookups
|
||||||
f.dirCache.Put(remote, *node.Id)
|
f.dirCache.Put(remote, *node.Id)
|
||||||
when, _ := time.Parse(timeFormat, *node.ModifiedDate) // FIXME
|
when, _ := time.Parse(timeFormat, *node.ModifiedDate) // FIXME
|
||||||
d := fs.NewDir(remote, when)
|
d := fs.NewDir(remote, when).SetID(*node.Id)
|
||||||
entries = append(entries, d)
|
entries = append(entries, d)
|
||||||
case fileKind:
|
case fileKind:
|
||||||
o, err := f.newObjectWithInfo(remote, node)
|
o, err := f.newObjectWithInfo(remote, node)
|
||||||
|
@ -454,7 +454,7 @@ func (f *Fs) List(dir string) (entries fs.DirEntries, err error) {
|
|||||||
if info.Type == api.ItemTypeFolder {
|
if info.Type == api.ItemTypeFolder {
|
||||||
// cache the directory ID for later lookups
|
// cache the directory ID for later lookups
|
||||||
f.dirCache.Put(remote, info.ID)
|
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?
|
// FIXME more info from dir?
|
||||||
entries = append(entries, d)
|
entries = append(entries, d)
|
||||||
} else if info.Type == api.ItemTypeFile {
|
} else if info.Type == api.ItemTypeFile {
|
||||||
|
@ -591,7 +591,7 @@ func (f *Fs) List(dir string) (entries fs.DirEntries, err error) {
|
|||||||
// cache the directory ID for later lookups
|
// cache the directory ID for later lookups
|
||||||
f.dirCache.Put(remote, item.Id)
|
f.dirCache.Put(remote, item.Id)
|
||||||
when, _ := time.Parse(timeFormatIn, item.ModifiedDate)
|
when, _ := time.Parse(timeFormatIn, item.ModifiedDate)
|
||||||
d := fs.NewDir(remote, when)
|
d := fs.NewDir(remote, when).SetID(item.Id)
|
||||||
entries = append(entries, d)
|
entries = append(entries, d)
|
||||||
case item.Md5Checksum != "" || item.FileSize > 0:
|
case item.Md5Checksum != "" || item.FileSize > 0:
|
||||||
// If item has MD5 sum or a length it is a file stored on drive
|
// If item has MD5 sum or a length it is a file stored on drive
|
||||||
|
12
fs/dir.go
12
fs/dir.go
@ -8,6 +8,7 @@ type Dir struct {
|
|||||||
modTime time.Time // modification or creation time - IsZero for unknown
|
modTime time.Time // modification or creation time - IsZero for unknown
|
||||||
size int64 // size of directory and contents or -1 if unknown
|
size int64 // size of directory and contents or -1 if unknown
|
||||||
items int64 // number of objects or -1 for unknown
|
items int64 // number of objects or -1 for unknown
|
||||||
|
id string // optional ID
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDir creates an unspecialized Directory object
|
// NewDir creates an unspecialized Directory object
|
||||||
@ -46,6 +47,17 @@ func (d *Dir) SetRemote(remote string) *Dir {
|
|||||||
return d
|
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
|
// ModTime returns the modification date of the file
|
||||||
// It should return a best guess if one isn't available
|
// It should return a best guess if one isn't available
|
||||||
func (d *Dir) ModTime() time.Time {
|
func (d *Dir) ModTime() time.Time {
|
||||||
|
4
fs/fs.go
4
fs/fs.go
@ -219,6 +219,10 @@ type Directory interface {
|
|||||||
// Items returns the count of items in this directory or this
|
// Items returns the count of items in this directory or this
|
||||||
// directory and subdirectories if known, -1 for unknown
|
// directory and subdirectories if known, -1 for unknown
|
||||||
Items() int64
|
Items() int64
|
||||||
|
|
||||||
|
// ID returns the internal ID of this directory if known, or
|
||||||
|
// "" otherwise
|
||||||
|
ID() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// MimeTyper is an optional interface for Object
|
// MimeTyper is an optional interface for Object
|
||||||
|
@ -423,7 +423,7 @@ func (f *Fs) List(dir string) (entries fs.DirEntries, err error) {
|
|||||||
if info.Folder != nil {
|
if info.Folder != nil {
|
||||||
// cache the directory ID for later lookups
|
// cache the directory ID for later lookups
|
||||||
f.dirCache.Put(remote, info.ID)
|
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 {
|
if info.Folder != nil {
|
||||||
d.SetItems(info.Folder.ChildCount)
|
d.SetItems(info.Folder.ChildCount)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user