aboutsummaryrefslogtreecommitdiff
path: root/weed/command/mount_std.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2016-06-02 18:09:14 -0700
committerChris Lu <chris.lu@gmail.com>2016-06-02 18:09:14 -0700
commit5ce6bbf07672bf3f3c8d26cd2ce0e3e853a47c44 (patch)
tree2e4dd2ad0a618ab2b7cdebcdb9c503526c31e2e8 /weed/command/mount_std.go
parentcaeffa3998adc060fa66c4cd77af971ff2d26c57 (diff)
downloadseaweedfs-5ce6bbf07672bf3f3c8d26cd2ce0e3e853a47c44.tar.xz
seaweedfs-5ce6bbf07672bf3f3c8d26cd2ce0e3e853a47c44.zip
directory structure change to work with glide
glide has its own requirements. My previous workaround caused me some code checkin errors. Need to fix this.
Diffstat (limited to 'weed/command/mount_std.go')
-rw-r--r--weed/command/mount_std.go106
1 files changed, 106 insertions, 0 deletions
diff --git a/weed/command/mount_std.go b/weed/command/mount_std.go
new file mode 100644
index 000000000..b086d8cbf
--- /dev/null
+++ b/weed/command/mount_std.go
@@ -0,0 +1,106 @@
+// +build linux darwin
+
+package command
+
+import (
+ "fmt"
+ "runtime"
+
+ "bazil.org/fuse"
+ "bazil.org/fuse/fs"
+ "github.com/chrislusf/seaweedfs/weed/filer"
+ "github.com/chrislusf/seaweedfs/weed/glog"
+ "github.com/chrislusf/seaweedfs/weed/storage"
+ "github.com/chrislusf/seaweedfs/weed/util"
+ "golang.org/x/net/context"
+)
+
+func runMount(cmd *Command, args []string) bool {
+ fmt.Printf("This is SeaweedFS version %s %s %s\n", util.VERSION, runtime.GOOS, runtime.GOARCH)
+ if *mountOptions.dir == "" {
+ fmt.Printf("Please specify the mount directory via \"-dir\"")
+ return false
+ }
+
+ c, err := fuse.Mount(*mountOptions.dir)
+ if err != nil {
+ glog.Fatal(err)
+ return false
+ }
+
+ OnInterrupt(func() {
+ fuse.Unmount(*mountOptions.dir)
+ c.Close()
+ })
+
+ err = fs.Serve(c, WFS{})
+ if err != nil {
+ fuse.Unmount(*mountOptions.dir)
+ }
+
+ // check if the mount process has an error to report
+ <-c.Ready
+ if err := c.MountError; err != nil {
+ glog.Fatal(err)
+ }
+
+ return true
+}
+
+type File struct {
+ FileId filer.FileId
+ Name string
+}
+
+func (File) Attr(context context.Context, attr *fuse.Attr) error {
+ return nil
+}
+func (File) ReadAll(ctx context.Context) ([]byte, error) {
+ return []byte("hello, world\n"), nil
+}
+
+type Dir struct {
+ Path string
+ Id uint64
+}
+
+func (dir Dir) Attr(context context.Context, attr *fuse.Attr) error {
+ return nil
+}
+
+func (dir Dir) Lookup(ctx context.Context, name string) (fs.Node, error) {
+ files_result, e := filer.ListFiles(*mountOptions.filer, dir.Path, name)
+ if e != nil {
+ return nil, fuse.ENOENT
+ }
+ if len(files_result.Files) > 0 {
+ return File{files_result.Files[0].Id, files_result.Files[0].Name}, nil
+ }
+ return nil, fmt.Errorf("File Not Found for %s", name)
+}
+
+type WFS struct{}
+
+func (WFS) Root() (fs.Node, error) {
+ return Dir{}, nil
+}
+
+func (dir *Dir) ReadDir(ctx context.Context) ([]fuse.Dirent, error) {
+ var ret []fuse.Dirent
+ if dirs, e := filer.ListDirectories(*mountOptions.filer, dir.Path); e == nil {
+ for _, d := range dirs.Directories {
+ dirId := uint64(d.Id)
+ ret = append(ret, fuse.Dirent{Inode: dirId, Name: d.Name, Type: fuse.DT_Dir})
+ }
+ }
+ if files, e := filer.ListFiles(*mountOptions.filer, dir.Path, ""); e == nil {
+ for _, f := range files.Files {
+ if fileId, e := storage.ParseFileId(string(f.Id)); e == nil {
+ fileInode := uint64(fileId.VolumeId)<<48 + fileId.Key
+ ret = append(ret, fuse.Dirent{Inode: fileInode, Name: f.Name, Type: fuse.DT_File})
+ }
+
+ }
+ }
+ return ret, nil
+}