1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
13 type staleChecker struct {
18 func (sc *staleChecker) DoIfStale(fn func(), staleFunc func(time.Time) bool) {
21 if !staleFunc(sc.last) {
28 // projectnode exposes an Arvados project as a filesystem directory.
29 type projectnode struct {
36 func (pn *projectnode) load() {
37 fs := pn.FS().(*customFileSystem)
41 pn.err = fs.RequestAndDecode(&resp, "GET", "arvados/v1/users/current", nil, nil)
47 filters := []Filter{{"owner_uuid", "=", pn.uuid}}
48 params := ResourceListParams{
53 var resp CollectionList
54 pn.err = fs.RequestAndDecode(&resp, "GET", "arvados/v1/collections", nil, params)
58 if len(resp.Items) == 0 {
61 for _, i := range resp.Items {
66 pn.inode.Child(coll.Name, func(inode) (inode, error) {
67 return deferredCollectionFS(fs, pn, coll), nil
70 params.Filters = append(filters, Filter{"uuid", ">", resp.Items[len(resp.Items)-1].UUID})
73 filters = append(filters, Filter{"group_class", "=", "project"})
74 params.Filters = filters
77 pn.err = fs.RequestAndDecode(&resp, "GET", "arvados/v1/groups", nil, params)
81 if len(resp.Items) == 0 {
84 for _, group := range resp.Items {
85 if group.Name == "" || group.Name == "." || group.Name == ".." {
88 pn.inode.Child(group.Name, func(inode) (inode, error) {
89 return fs.newProjectNode(pn, group.Name, group.UUID), nil
92 params.Filters = append(filters, Filter{"uuid", ">", resp.Items[len(resp.Items)-1].UUID})
97 func (pn *projectnode) Readdir() ([]os.FileInfo, error) {
98 pn.staleChecker.DoIfStale(pn.load, pn.FS().(*customFileSystem).Stale)
102 return pn.inode.Readdir()
105 func (pn *projectnode) Child(name string, replace func(inode) (inode, error)) (inode, error) {
106 pn.staleChecker.DoIfStale(pn.load, pn.FS().(*customFileSystem).Stale)
112 return pn.inode.Child(name, nil)
114 return pn.inode.Child(name, func(existing inode) (inode, error) {
115 if repl, err := replace(existing); err != nil {
117 } else if repl == nil {
123 return existing, ErrInvalidArgument
124 } else if existing != nil {
126 return existing, ErrInvalidArgument
127 } else if repl.FileInfo().IsDir() {
129 // TODO: repl.SetParent(pn, name), etc.
130 return existing, ErrInvalidArgument
133 return existing, ErrInvalidArgument