1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
14 func deferredCollectionFS(fs FileSystem, parent inode, coll Collection) inode {
16 if coll.ModifiedAt != nil {
17 modTime = *coll.ModifiedAt
21 placeholder := &treenode{
28 mode: 0755 | os.ModeDir,
31 return &deferrednode{wrapped: placeholder, create: func() inode {
32 err := fs.RequestAndDecode(&coll, "GET", "arvados/v1/collections/"+coll.UUID, nil, nil)
34 log.Printf("BUG: unhandled error: %s", err)
37 cfs, err := coll.FileSystem(fs, fs)
39 log.Printf("BUG: unhandled error: %s", err)
42 root := cfs.rootnode()
43 root.SetParent(parent, coll.Name)
48 // A deferrednode wraps an inode that's expensive to build. Initially,
49 // it responds to basic directory functions by proxying to the given
50 // placeholder. If a caller uses a read/write/lock operation,
51 // deferrednode calls the create() func to create the real inode, and
52 // proxies to the real inode from then on.
54 // In practice, this means a deferrednode's parent's directory listing
55 // can be generated using only the placeholder, instead of waiting for
57 type deferrednode struct {
64 func (dn *deferrednode) realinode() inode {
68 dn.wrapped = dn.create()
74 func (dn *deferrednode) currentinode() inode {
80 func (dn *deferrednode) Read(p []byte, pos filenodePtr) (int, filenodePtr, error) {
81 return dn.realinode().Read(p, pos)
84 func (dn *deferrednode) Write(p []byte, pos filenodePtr) (int, filenodePtr, error) {
85 return dn.realinode().Write(p, pos)
88 func (dn *deferrednode) Child(name string, replace func(inode) (inode, error)) (inode, error) {
89 return dn.realinode().Child(name, replace)
92 func (dn *deferrednode) Truncate(size int64) error { return dn.realinode().Truncate(size) }
93 func (dn *deferrednode) SetParent(p inode, name string) { dn.realinode().SetParent(p, name) }
94 func (dn *deferrednode) IsDir() bool { return dn.currentinode().IsDir() }
95 func (dn *deferrednode) Readdir() ([]os.FileInfo, error) { return dn.realinode().Readdir() }
96 func (dn *deferrednode) Size() int64 { return dn.currentinode().Size() }
97 func (dn *deferrednode) FileInfo() os.FileInfo { return dn.currentinode().FileInfo() }
98 func (dn *deferrednode) Lock() { dn.realinode().Lock() }
99 func (dn *deferrednode) Unlock() { dn.realinode().Unlock() }
100 func (dn *deferrednode) RLock() { dn.realinode().RLock() }
101 func (dn *deferrednode) RUnlock() { dn.realinode().RUnlock() }
102 func (dn *deferrednode) FS() FileSystem { return dn.currentinode().FS() }
103 func (dn *deferrednode) Parent() inode { return dn.currentinode().Parent() }