From e2d7d413efc453775f82f53bca733fb574e5c5f7 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 30 Jun 2017 10:54:14 +0100 Subject: [PATCH] fs: rename BasicInfo to DirEntry --- b2/b2.go | 4 ++-- cmd/mount/dir.go | 2 +- cmd/mountlib/dir.go | 6 +++--- fs/fs.go | 14 ++++++-------- fs/operations.go | 2 +- fs/operations_test.go | 2 +- fs/sync.go | 8 ++++---- fs/walk.go | 6 +++--- googlecloudstorage/googlecloudstorage.go | 4 ++-- s3/s3.go | 4 ++-- swift/swift.go | 8 ++++---- yandex/yandex.go | 4 ++-- 12 files changed, 31 insertions(+), 33 deletions(-) diff --git a/b2/b2.go b/b2/b2.go index 7a880770e..5a060f451 100644 --- a/b2/b2.go +++ b/b2/b2.go @@ -518,8 +518,8 @@ func (f *Fs) list(dir string, recurse bool, prefix string, limit int, hidden boo return nil } -// Convert a list item into a BasicInfo -func (f *Fs) itemToDirEntry(remote string, object *api.File, isDirectory bool, last *string) (fs.BasicInfo, error) { +// Convert a list item into a DirEntry +func (f *Fs) itemToDirEntry(remote string, object *api.File, isDirectory bool, last *string) (fs.DirEntry, error) { if isDirectory { d := &fs.Dir{ Name: remote, diff --git a/cmd/mount/dir.go b/cmd/mount/dir.go index fed300ca5..cba5ce8cb 100644 --- a/cmd/mount/dir.go +++ b/cmd/mount/dir.go @@ -21,7 +21,7 @@ import ( // // node may be nil, but o may not type DirEntry struct { - o fs.BasicInfo + o fs.DirEntry node fusefs.Node } diff --git a/cmd/mountlib/dir.go b/cmd/mountlib/dir.go index e51401232..2f58adc6c 100644 --- a/cmd/mountlib/dir.go +++ b/cmd/mountlib/dir.go @@ -16,7 +16,7 @@ import ( // // node may be nil, but o may not type DirEntry struct { - Obj fs.BasicInfo + Obj fs.DirEntry Node Node } @@ -123,7 +123,7 @@ func (d *Dir) rename(newParent *Dir, fsDir *fs.Dir) { // addObject adds a new object or directory to the directory // // note that we add new objects rather than updating old ones -func (d *Dir) addObject(o fs.BasicInfo, node Node) *DirEntry { +func (d *Dir) addObject(o fs.DirEntry, node Node) *DirEntry { item := &DirEntry{ Obj: o, Node: node, @@ -414,7 +414,7 @@ func (d *Dir) Rename(oldName, newName string, destDir *Dir) error { fs.Errorf(oldPath, "Dir.Rename error: %v", err) return err } - var newObj fs.BasicInfo + var newObj fs.DirEntry oldNode := oldItem.Node switch x := oldItem.Obj.(type) { case fs.Object: diff --git a/fs/fs.go b/fs/fs.go index 9c2c0a144..4ba918190 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -178,7 +178,7 @@ type Object interface { // ObjectInfo provides read only information about an object. type ObjectInfo interface { - BasicInfo + DirEntry // Fs returns read only access to the Fs that this object is part of Fs() Info @@ -191,9 +191,10 @@ type ObjectInfo interface { Storable() bool } -// BasicInfo provides read only information about the common subset of -// a Dir or Object. -type BasicInfo interface { +// DirEntry provides read only information about the common subset of +// a Dir or Object. These are returned from directory listings - type +// assert them into the correct type. +type DirEntry interface { // String returns a description of the Object String() string @@ -576,10 +577,7 @@ func (d *Dir) Size() int64 { } // Check interface -var _ BasicInfo = (*Dir)(nil) - -// DirChan is a channel of Dir objects -type DirChan chan *Dir +var _ DirEntry = (*Dir)(nil) // Find looks for an Info object for the name passed in // diff --git a/fs/operations.go b/fs/operations.go index a0d39e09c..2377484dd 100644 --- a/fs/operations.go +++ b/fs/operations.go @@ -525,7 +525,7 @@ func readFilesFn(fs Fs, includeAll bool, dir string, add func(Object) error) (er } // DirEntries is a slice of Object or *Dir -type DirEntries []BasicInfo +type DirEntries []DirEntry // Len is part of sort.Interface. func (ds DirEntries) Len() int { diff --git a/fs/operations_test.go b/fs/operations_test.go index c184a22cb..4fa7c07e6 100644 --- a/fs/operations_test.go +++ b/fs/operations_test.go @@ -952,7 +952,7 @@ func TestListDirSorted(t *testing.T) { var items fs.DirEntries var err error - // Turn the BasicInfo into a name, ending with a / if it is a + // Turn the DirEntry into a name, ending with a / if it is a // dir str := func(i int) string { item := items[i] diff --git a/fs/sync.go b/fs/sync.go index 95c972cc9..61f676759 100644 --- a/fs/sync.go +++ b/fs/sync.go @@ -738,7 +738,7 @@ func (s *syncCopyMove) run() error { } // Have an object which is in the destination only -func (s *syncCopyMove) dstOnly(dst BasicInfo, job listDirJob, jobs *[]listDirJob) { +func (s *syncCopyMove) dstOnly(dst DirEntry, job listDirJob, jobs *[]listDirJob) { if s.deleteMode == DeleteModeOff { return } @@ -771,7 +771,7 @@ func (s *syncCopyMove) dstOnly(dst BasicInfo, job listDirJob, jobs *[]listDirJob } // Have an object which is in the source only -func (s *syncCopyMove) srcOnly(src BasicInfo, job listDirJob, jobs *[]listDirJob) { +func (s *syncCopyMove) srcOnly(src DirEntry, job listDirJob, jobs *[]listDirJob) { if s.deleteMode == DeleteModeOnly { return } @@ -799,7 +799,7 @@ func (s *syncCopyMove) srcOnly(src BasicInfo, job listDirJob, jobs *[]listDirJob } // Given a src and a dst, transfer the src to dst -func (s *syncCopyMove) transfer(dst, src BasicInfo, job listDirJob, jobs *[]listDirJob) { +func (s *syncCopyMove) transfer(dst, src DirEntry, job listDirJob, jobs *[]listDirJob) { switch srcX := src.(type) { case Object: if s.deleteMode == DeleteModeOnly { @@ -878,7 +878,7 @@ func (s *syncCopyMove) _run(job listDirJob) (jobs []listDirJob) { if s.aborting() { return nil } - var src, dst BasicInfo + var src, dst DirEntry if iSrc < len(srcList) { src = srcList[iSrc] } diff --git a/fs/walk.go b/fs/walk.go index a52569393..c3ada147e 100644 --- a/fs/walk.go +++ b/fs/walk.go @@ -187,13 +187,13 @@ func parentDir(entryPath string) string { } // add an entry to the tree -func (dt DirTree) add(entry BasicInfo) { +func (dt DirTree) add(entry DirEntry) { dirPath := parentDir(entry.Remote()) dt[dirPath] = append(dt[dirPath], entry) } // add a directory entry to the tree -func (dt DirTree) addDir(entry BasicInfo) { +func (dt DirTree) addDir(entry DirEntry) { dt.add(entry) // create the directory itself if it doesn't exist already dirPath := entry.Remote() @@ -402,7 +402,7 @@ func (lh *ListRHelper) send(max int) (err error) { // Add an entry to the stored entries and send them if there are more // than a certain amount -func (lh *ListRHelper) Add(entry BasicInfo) error { +func (lh *ListRHelper) Add(entry DirEntry) error { if entry == nil { return nil } diff --git a/googlecloudstorage/googlecloudstorage.go b/googlecloudstorage/googlecloudstorage.go index 4218c5492..00a3d7d86 100644 --- a/googlecloudstorage/googlecloudstorage.go +++ b/googlecloudstorage/googlecloudstorage.go @@ -360,8 +360,8 @@ func (f *Fs) list(dir string, recurse bool, fn listFn) error { return nil } -// Convert a list item into a BasicInfo -func (f *Fs) itemToDirEntry(remote string, object *storage.Object, isDirectory bool) (fs.BasicInfo, error) { +// Convert a list item into a DirEntry +func (f *Fs) itemToDirEntry(remote string, object *storage.Object, isDirectory bool) (fs.DirEntry, error) { if isDirectory { d := &fs.Dir{ Name: remote, diff --git a/s3/s3.go b/s3/s3.go index 23869c255..5166b4437 100644 --- a/s3/s3.go +++ b/s3/s3.go @@ -548,8 +548,8 @@ func (f *Fs) list(dir string, recurse bool, fn listFn) error { return nil } -// Convert a list item into a BasicInfo -func (f *Fs) itemToDirEntry(remote string, object *s3.Object, isDirectory bool) (fs.BasicInfo, error) { +// Convert a list item into a DirEntry +func (f *Fs) itemToDirEntry(remote string, object *s3.Object, isDirectory bool) (fs.DirEntry, error) { if isDirectory { size := int64(0) if object.Size != nil { diff --git a/swift/swift.go b/swift/swift.go index 344317e70..b362f72ba 100644 --- a/swift/swift.go +++ b/swift/swift.go @@ -315,7 +315,7 @@ func (f *Fs) listContainerRoot(container, root string, dir string, recurse bool, }) } -type addEntryFn func(fs.BasicInfo) error +type addEntryFn func(fs.DirEntry) error // list the objects into the function supplied func (f *Fs) list(dir string, recurse bool, fn addEntryFn) error { @@ -347,7 +347,7 @@ func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) { return nil, fs.ErrorListBucketRequired } // List the objects - err = f.list(dir, false, func(entry fs.BasicInfo) error { + err = f.list(dir, false, func(entry fs.DirEntry) error { entries = append(entries, entry) return nil }) @@ -417,7 +417,7 @@ func (f *Fs) ListR(dir string, callback fs.ListRCallback) (err error) { return errors.New("container needed for recursive list") } list := fs.NewListRHelper(callback) - err = f.list(dir, true, func(entry fs.BasicInfo) error { + err = f.list(dir, true, func(entry fs.DirEntry) error { return list.Add(entry) }) if err != nil { @@ -493,7 +493,7 @@ func (f *Fs) Purge() error { go func() { delErr <- fs.DeleteFiles(toBeDeleted) }() - err := f.list("", true, func(entry fs.BasicInfo) error { + err := f.list("", true, func(entry fs.DirEntry) error { if o, ok := entry.(*Object); ok { toBeDeleted <- o } diff --git a/yandex/yandex.go b/yandex/yandex.go index 8e99d60ad..9d30724dd 100644 --- a/yandex/yandex.go +++ b/yandex/yandex.go @@ -166,8 +166,8 @@ func (f *Fs) setRoot(root string) { f.diskRoot = diskRoot } -// Convert a list item into a BasicInfo -func (f *Fs) itemToDirEntry(remote string, object *yandex.ResourceInfoResponse) (fs.BasicInfo, error) { +// Convert a list item into a DirEntry +func (f *Fs) itemToDirEntry(remote string, object *yandex.ResourceInfoResponse) (fs.DirEntry, error) { switch object.ResourceType { case "dir": t, err := time.Parse(time.RFC3339Nano, object.Modified)