16535: collectionFileSystem implements inode, eliminating wrapper.
authorTom Clegg <tom@tomclegg.ca>
Mon, 13 Jul 2020 15:57:37 +0000 (11:57 -0400)
committerTom Clegg <tom@tomclegg.ca>
Mon, 13 Jul 2020 15:57:37 +0000 (11:57 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@tomclegg.ca>

sdk/go/arvados/fs_collection.go
sdk/go/arvados/fs_deferred.go
sdk/go/arvados/fs_site.go

index 5970ec61208e0a183e9f16e2e53396f8ab5b85de..0edc48162b1a031b8487ac9b38997c0a4b6f3f4d 100644 (file)
@@ -121,6 +121,62 @@ func (fs *collectionFileSystem) newNode(name string, perm os.FileMode, modTime t
        }
 }
 
+func (fs *collectionFileSystem) Child(name string, replace func(inode) (inode, error)) (inode, error) {
+       return fs.rootnode().Child(name, replace)
+}
+
+func (fs *collectionFileSystem) FS() FileSystem {
+       return fs
+}
+
+func (fs *collectionFileSystem) FileInfo() os.FileInfo {
+       return fs.rootnode().FileInfo()
+}
+
+func (fs *collectionFileSystem) IsDir() bool {
+       return true
+}
+
+func (fs *collectionFileSystem) Lock() {
+       fs.rootnode().Lock()
+}
+
+func (fs *collectionFileSystem) Unlock() {
+       fs.rootnode().Unlock()
+}
+
+func (fs *collectionFileSystem) RLock() {
+       fs.rootnode().RLock()
+}
+
+func (fs *collectionFileSystem) RUnlock() {
+       fs.rootnode().RUnlock()
+}
+
+func (fs *collectionFileSystem) Parent() inode {
+       return fs.rootnode().Parent()
+}
+
+func (fs *collectionFileSystem) Read(_ []byte, ptr filenodePtr) (int, filenodePtr, error) {
+       return 0, ptr, ErrInvalidOperation
+}
+
+func (fs *collectionFileSystem) Write(_ []byte, ptr filenodePtr) (int, filenodePtr, error) {
+       return 0, ptr, ErrInvalidOperation
+}
+
+func (fs *collectionFileSystem) Readdir() ([]os.FileInfo, error) {
+       return fs.rootnode().Readdir()
+}
+
+func (fs *collectionFileSystem) SetParent(parent inode, name string) {
+       fs.rootnode().SetParent(parent, name)
+}
+
+func (fs *collectionFileSystem) Truncate(int64) error {
+       return ErrInvalidOperation
+}
+
 func (fs *collectionFileSystem) Sync() error {
        if fs.uuid == "" {
                return nil
@@ -193,25 +249,6 @@ func (fs *collectionFileSystem) Size() int64 {
        return fs.fileSystem.root.(*dirnode).TreeSize()
 }
 
-// asChildNode() repackages fs as an inode that can be used as a child
-// node in a different fs. Not goroutine-safe.
-//
-// After calling asChildNode(), the caller should not use fs directly.
-func (fs *collectionFileSystem) asChildNode(parent inode, name string) *collectionfsnode {
-       root := fs.rootnode().(*dirnode)
-       root.SetParent(parent, name)
-       return &collectionfsnode{dirnode: root, fs: fs}
-}
-
-type collectionfsnode struct {
-       *dirnode
-       fs *collectionFileSystem
-}
-
-func (cn *collectionfsnode) Sync() error {
-       return cn.fs.Sync()
-}
-
 // filenodePtr is an offset into a file that is (usually) efficient to
 // seek to. Specifically, if filenode.repacked==filenodePtr.repacked
 // then
index 4eb48b2f77bdde92736c22cb3be1c1789c0ae825..1f888a4e8dd44c37fb628d4d95ce05f555137105 100644 (file)
@@ -32,12 +32,14 @@ func deferredCollectionFS(fs FileSystem, parent inode, coll Collection) inode {
                        log.Printf("BUG: unhandled error: %s", err)
                        return placeholder
                }
-               cfs, err := coll.FileSystem(fs, fs)
+               newfs, err := coll.FileSystem(fs, fs)
                if err != nil {
                        log.Printf("BUG: unhandled error: %s", err)
                        return placeholder
                }
-               return cfs.(*collectionFileSystem).asChildNode(parent, coll.Name)
+               cfs := newfs.(*collectionFileSystem)
+               cfs.SetParent(parent, coll.Name)
+               return cfs
        }}
 }
 
index 2e131c33f89d54c7f476f4418417d81f1b3b19b6..8b61ccfd6ecb13593f4df719f3eb256aeb3353b0 100644 (file)
@@ -183,11 +183,13 @@ func (fs *customFileSystem) mountCollection(parent inode, id string) inode {
        if err != nil {
                return nil
        }
-       cfs, err := coll.FileSystem(fs, fs)
+       newfs, err := coll.FileSystem(fs, fs)
        if err != nil {
                return nil
        }
-       return cfs.(*collectionFileSystem).asChildNode(parent, id)
+       cfs := newfs.(*collectionFileSystem)
+       cfs.SetParent(parent, id)
+       return cfs
 }
 
 func (fs *customFileSystem) newProjectNode(root inode, name, uuid string) inode {