1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
12 type siteFileSystem struct {
16 // SiteFileSystem returns a FileSystem that maps collections and other
17 // Arvados objects onto a filesystem layout.
19 // This is experimental: the filesystem layout is not stable, and
20 // there are significant known bugs and shortcomings. For example,
21 // writes are not persisted until Sync() is called.
22 func (c *Client) SiteFileSystem(kc keepClient) FileSystem {
24 fs := &siteFileSystem{
25 fileSystem: fileSystem{
26 fsBackend: keepBackend{apiClient: c, keepClient: kc},
30 root.inode = &treenode{
35 mode: os.ModeDir | 0755,
38 inodes: make(map[string]inode),
40 root.inode.Child("by_id", func(inode) inode {
46 inodes: make(map[string]inode),
50 mode: 0755 | os.ModeDir,
53 create: fs.mountCollection,
60 func (fs *siteFileSystem) newNode(name string, perm os.FileMode, modTime time.Time) (node inode, err error) {
61 return nil, ErrInvalidOperation
64 func (fs *siteFileSystem) mountCollection(parent inode, id string) inode {
66 err := fs.RequestAndDecode(&coll, "GET", "arvados/v1/collections/"+id, nil, nil)
70 cfs, err := coll.FileSystem(fs, fs)
74 root := cfs.rootnode()
75 root.SetParent(parent, id)
79 // vdirnode wraps an inode by ignoring any requests to add/replace
80 // children, and calling a create() func when a non-existing child is
83 // create() can return either a new node, which will be added to the
84 // treenode, or nil for ENOENT.
85 type vdirnode struct {
87 create func(parent inode, name string) inode
90 func (vn *vdirnode) Child(name string, _ func(inode) inode) inode {
91 return vn.inode.Child(name, func(existing inode) inode {
94 } else if vn.create == nil {
97 n := vn.create(vn, name)
100 vn.inode.(*treenode).fileinfo.modTime = time.Now()