X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/eee302a3157296bccf40e9b83f52c2952294a04e..b041a675c577e174680913e0da0bf69b1cca83b6:/sdk/go/arvados/fs_site.go diff --git a/sdk/go/arvados/fs_site.go b/sdk/go/arvados/fs_site.go index 900893aa36..bb2eee7792 100644 --- a/sdk/go/arvados/fs_site.go +++ b/sdk/go/arvados/fs_site.go @@ -54,6 +54,8 @@ func (c *Client) CustomFileSystem(kc keepClient) CustomFileSystem { } func (fs *customFileSystem) MountByID(mount string) { + fs.root.treenode.Lock() + defer fs.root.treenode.Unlock() fs.root.treenode.Child(mount, func(inode) (inode, error) { return &vdirnode{ treenode: treenode{ @@ -72,12 +74,16 @@ func (fs *customFileSystem) MountByID(mount string) { } func (fs *customFileSystem) MountProject(mount, uuid string) { + fs.root.treenode.Lock() + defer fs.root.treenode.Unlock() fs.root.treenode.Child(mount, func(inode) (inode, error) { - return fs.newProjectNode(fs.root, mount, uuid), nil + return fs.newProjectNode(fs.root, mount, uuid, nil), nil }) } func (fs *customFileSystem) MountUsers(mount string) { + fs.root.treenode.Lock() + defer fs.root.treenode.Unlock() fs.root.treenode.Child(mount, func(inode) (inode, error) { return &lookupnode{ stale: fs.Stale, @@ -127,14 +133,14 @@ func (fs *customFileSystem) Stale(t time.Time) bool { } func (fs *customFileSystem) newNode(name string, perm os.FileMode, modTime time.Time) (node inode, err error) { - return nil, ErrInvalidArgument + return nil, ErrInvalidOperation } func (fs *customFileSystem) mountByID(parent inode, id string) inode { if strings.Contains(id, "-4zz18-") || pdhRegexp.MatchString(id) { return fs.mountCollection(parent, id) } else if strings.Contains(id, "-j7d0g-") { - return fs.newProjectNode(fs.root, id, id) + return fs.newProjectNode(fs.root, id, id, nil) } else { return nil } @@ -155,7 +161,8 @@ func (fs *customFileSystem) mountCollection(parent inode, id string) inode { return cfs } -func (fs *customFileSystem) newProjectNode(root inode, name, uuid string) inode { +func (fs *customFileSystem) newProjectNode(root inode, name, uuid string, proj *Group) inode { + var projLoading sync.Mutex return &lookupnode{ stale: fs.Stale, loadOne: func(parent inode, name string) (inode, error) { return fs.projectsLoadOne(parent, uuid, name) }, @@ -168,12 +175,26 @@ func (fs *customFileSystem) newProjectNode(root inode, name, uuid string) inode name: name, modTime: time.Now(), mode: 0755 | os.ModeDir, + sys: func() interface{} { + projLoading.Lock() + defer projLoading.Unlock() + if proj != nil { + return proj + } + var g Group + err := fs.RequestAndDecode(&g, "GET", "arvados/v1/groups/"+uuid, nil, nil) + if err != nil { + return err + } + proj = &g + return proj + }, }, }, } } -// vdirnode wraps an inode by rejecting (with ErrInvalidArgument) +// vdirnode wraps an inode by rejecting (with ErrInvalidOperation) // calls that add/replace children directly, instead calling a // create() func when a non-existing child is looked up. // @@ -198,7 +219,7 @@ func (vn *vdirnode) Child(name string, replace func(inode) (inode, error)) (inod } else if tryRepl, err := replace(existing); err != nil { return existing, err } else if tryRepl != existing { - return existing, ErrInvalidArgument + return existing, ErrInvalidOperation } else { return existing, nil }