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 {
45 inodes: make(map[string]inode),
49 mode: 0755 | os.ModeDir,
52 create: fs.mountCollection,
55 root.inode.Child("home", func(inode) inode {
56 return fs.newProjectNode(fs.root, "home", "")
61 func (fs *siteFileSystem) newNode(name string, perm os.FileMode, modTime time.Time) (node inode, err error) {
62 return nil, ErrInvalidOperation
65 func (fs *siteFileSystem) mountCollection(parent inode, id string) inode {
67 err := fs.RequestAndDecode(&coll, "GET", "arvados/v1/collections/"+id, nil, nil)
71 cfs, err := coll.FileSystem(fs, fs)
75 root := cfs.rootnode()
76 root.SetParent(parent, id)
80 func (fs *siteFileSystem) newProjectNode(root inode, name, uuid string) inode {
86 inodes: make(map[string]inode),
90 mode: 0755 | os.ModeDir,
96 // vdirnode wraps an inode by ignoring any requests to add/replace
97 // children, and calling a create() func when a non-existing child is
100 // create() can return either a new node, which will be added to the
101 // treenode, or nil for ENOENT.
102 type vdirnode struct {
104 create func(parent inode, name string) inode
107 func (vn *vdirnode) Child(name string, _ func(inode) inode) inode {
108 return vn.inode.Child(name, func(existing inode) inode {
111 } else if vn.create == nil {
114 n := vn.create(vn, name)
116 n.SetParent(vn, name)
117 vn.inode.(*treenode).fileinfo.modTime = time.Now()