Created
October 14, 2017 16:58
-
-
Save nolash/f4ef109455916a5e67166589c56d689d to your computer and use it in GitHub Desktop.
Simple fuse mount and umount
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/ethereum/go-ethereum/log" | |
"github.com/ethereum/go-ethereum/swarm/api" | |
"github.com/ethereum/go-ethereum/swarm/fuse" | |
"github.com/ethereum/go-ethereum/swarm/storage" | |
"io/ioutil" | |
"os" | |
"os/signal" | |
"strings" | |
) | |
func init() { | |
log.Root().SetHandler(log.CallerFileHandler(log.LvlFilterHandler(log.LvlTrace, log.StdoutHandler))) | |
} | |
func main() { | |
ch := make(chan os.Signal) | |
dpadir, err := ioutil.TempDir("", "fusedpa") | |
if err != nil { | |
log.Crit(err.Error()) | |
} | |
defer os.RemoveAll(dpadir) | |
srcdir, err := ioutil.TempDir("", "fusesrc") | |
if err != nil { | |
log.Crit(err.Error()) | |
} | |
defer os.RemoveAll(srcdir) | |
mntdir, err := ioutil.TempDir("", "fusemnt") | |
if err != nil { | |
log.Crit(err.Error()) | |
} | |
defer os.RemoveAll(mntdir) | |
f, err := os.Create(strings.Join([]string{srcdir, "foo.txt"}, "/")) | |
if err != nil { | |
log.Crit(err.Error()) | |
} | |
_, err = f.Write([]byte("foo")) | |
if err != nil { | |
log.Crit(err.Error()) | |
} | |
f.Close() | |
dpa, err := storage.NewLocalDPA(dpadir) | |
if err != nil { | |
log.Crit(err.Error()) | |
} | |
dpa.Start() | |
defer dpa.Stop() | |
myapi := api.NewApi(dpa, nil) | |
mhash, err := myapi.Upload(srcdir, "") | |
if err != nil { | |
log.Crit(err.Error()) | |
} | |
myfuse := fuse.NewSwarmFS(myapi) | |
minfo, err := myfuse.Mount(mhash, mntdir) | |
if err != nil { | |
log.Crit(err.Error()) | |
} | |
defer myfuse.Unmount(mntdir) | |
log.Debug("mounts", "info", minfo, "list", myfuse.Listmounts()) | |
signal.Notify(ch, os.Interrupt) | |
<-ch | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment