tractor.dev/toolkit-go@v0.0.0-20241010005851-214d91207d07/engine/fs/mountfs/modifiers.go (about) 1 package mountfs 2 3 import ( 4 "io/fs" 5 6 "tractor.dev/toolkit-go/engine/fs/readonlyfs" 7 "tractor.dev/toolkit-go/engine/fs/unionfs" 8 "tractor.dev/toolkit-go/engine/fs/workingpathfs" 9 ) 10 11 type Modifier func(fs.FS, string, fs.FS) fs.FS 12 13 func Union() Modifier { 14 return func(fsys fs.FS, root string, mount fs.FS) fs.FS { 15 if root != "" && root != "." { 16 fsys = workingpathfs.New(fsys, root) 17 } 18 return unionfs.New(fsys, mount) 19 } 20 } 21 22 // func CopyOnWrite(overlay fs.FS) Modifier { 23 // return func(fsys fs.FS, root string, mount fs.FS) fs.FS { 24 // return afero.NewCopyOnWriteFs(mount, overlay) 25 // } 26 // } 27 28 // func CacheOnRead(cache fs.FS, cacheTime time.Duration) Modifier { 29 // return func(fsys fs.FS, root string, mount fs.FS) fs.FS { 30 // return afero.NewCacheOnReadFs(mount, cache, cacheTime) 31 // } 32 // } 33 34 func ReadOnly() Modifier { 35 return func(fsys fs.FS, root string, mount fs.FS) fs.FS { 36 return readonlyfs.New(mount) 37 } 38 }