github.com/hanwen/go-fuse@v1.0.0/unionfs/create.go (about) 1 // Copyright 2016 the Go-FUSE Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package unionfs 6 7 import ( 8 "os" 9 10 "github.com/hanwen/go-fuse/fuse/pathfs" 11 ) 12 13 func NewUnionFsFromRoots(roots []string, opts *UnionFsOptions, roCaching bool) (pathfs.FileSystem, error) { 14 fses := make([]pathfs.FileSystem, 0) 15 for i, r := range roots { 16 var fs pathfs.FileSystem 17 fi, err := os.Stat(r) 18 if err != nil { 19 return nil, err 20 } 21 if fi.IsDir() { 22 fs = pathfs.NewLoopbackFileSystem(r) 23 } 24 if fs == nil { 25 return nil, err 26 27 } 28 if i > 0 && roCaching { 29 fs = NewCachingFileSystem(fs, 0) 30 } 31 32 fses = append(fses, fs) 33 } 34 35 return NewUnionFs(fses, *opts) 36 }