Commit 13e7ad2c authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Add NewUnionFsFromRoots(), which automatically mounts zip/tar archives.

parent ef9991c3
...@@ -3,6 +3,7 @@ package main ...@@ -3,6 +3,7 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"log"
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/unionfs" "github.com/hanwen/go-fuse/unionfs"
"os" "os"
...@@ -28,16 +29,14 @@ func main() { ...@@ -28,16 +29,14 @@ func main() {
DeletionDirName: *deldirname, DeletionDirName: *deldirname,
} }
fses := make([]fuse.FileSystem, 0) ufs, err := unionfs.NewUnionFsFromRoots(flag.Args()[1:], &ufsOptions)
for _, r := range flag.Args()[1:] { if err != nil {
fses = append(fses, fuse.NewLoopbackFileSystem(r)) log.Fatal("Cannot create UnionFs", err)
os.Exit(1)
} }
ufs := unionfs.NewUnionFs("unionfs", fses, ufsOptions)
mountState, _, err := fuse.MountFileSystem(flag.Arg(0), ufs, nil) mountState, _, err := fuse.MountFileSystem(flag.Arg(0), ufs, nil)
if err != nil { if err != nil {
fmt.Printf("Mount fail: %v\n", err) log.Fatal("Mount fail:", err)
os.Exit(1)
} }
mountState.Debug = *debug mountState.Debug = *debug
......
...@@ -7,7 +7,8 @@ GOFILES=unionfs.go \ ...@@ -7,7 +7,8 @@ GOFILES=unionfs.go \
timedcache.go \ timedcache.go \
cachingfs.go \ cachingfs.go \
autounion.go \ autounion.go \
create.go
DEPS=../fuse DEPS=../fuse ../zipfs
include $(GOROOT)/src/Make.pkg include $(GOROOT)/src/Make.pkg
...@@ -93,15 +93,13 @@ func (me *AutoUnionFs) createFs(name string, roots []string) (*UnionFs, fuse.Sta ...@@ -93,15 +93,13 @@ func (me *AutoUnionFs) createFs(name string, roots []string) (*UnionFs, fuse.Sta
return gofs, fuse.OK return gofs, fuse.OK
} }
fses := make([]fuse.FileSystem, 0) ufs, err := NewUnionFsFromRoots(roots, &me.options.UnionFsOptions)
for _, r := range roots { if err != nil {
fses = append(fses, fuse.NewLoopbackFileSystem(r)) log.Println("Could not create UnionFs:", err)
return nil, fuse.EPERM
} }
identifier := fmt.Sprintf("%v", roots)
log.Println("Adding UnionFs for", identifier)
gofs = NewUnionFs(identifier, fses, me.options.UnionFsOptions)
me.knownFileSystems[name] = gofs me.knownFileSystems[name] = ufs
me.nameRootMap[name] = roots[0] me.nameRootMap[name] = roots[0]
return gofs, fuse.OK return gofs, fuse.OK
......
package unionfs
import (
"fmt"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/zipfs"
"log"
"os"
)
func NewUnionFsFromRoots(roots []string, opts *UnionFsOptions) (*UnionFs, os.Error) {
fses := make([]fuse.FileSystem, 0)
for _, r := range roots {
var fs fuse.FileSystem
fi, err := os.Stat(r)
if err != nil {
return nil, err
}
if fi.IsDirectory() {
fs = fuse.NewLoopbackFileSystem(r)
}
if fs == nil {
fs, err = zipfs.NewArchiveFileSystem(r)
}
if fs == nil {
return nil, err
}
fses = append(fses, fs)
}
identifier := fmt.Sprintf("%v", roots)
log.Println("Adding UnionFs for", identifier)
return NewUnionFs(identifier, fses, *opts), nil
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment