Commit 7a4491ad authored by Matt Bell's avatar Matt Bell Committed by Juan Batiz-Benet

Added --mount flag to mount when running 'ipfs daemon'

parent 105f2321
......@@ -18,6 +18,9 @@ import (
const (
initOptionKwd = "init"
mountKwd = "mount"
ipfsMountKwd = "mount-ipfs"
ipnsMountKwd = "mount-ipns"
)
var daemonCmd = &cmds.Command{
......@@ -34,12 +37,24 @@ the daemon.
Options: []cmds.Option{
cmds.BoolOption(initOptionKwd, "Initialize IPFS with default settings if not already initialized"),
cmds.BoolOption(mountKwd, "Mounts IPFS to the filesystem"),
cmds.StringOption(ipfsMountKwd, "Path to the mountpoint for IPFS (if using --mount)"),
cmds.StringOption(ipnsMountKwd, "Path to the mountpoint for IPNS (if using --mount)"),
},
Subcommands: map[string]*cmds.Command{},
Run: daemonFunc,
}
func daemonFunc(req cmds.Request) (interface{}, error) {
cfg, err := req.Context().GetConfig()
if err != nil {
return nil, err
}
node, err := core.NewIpfsNode(cfg, true)
if err != nil {
return nil, err
}
initialize, _, err := req.Option(initOptionKwd).Bool()
if err != nil {
......@@ -65,30 +80,49 @@ func daemonFunc(req cmds.Request) (interface{}, error) {
}
defer lock.Close()
cfg, err := req.Context().GetConfig()
if err != nil {
return nil, err
}
// setup function that constructs the context. we have to do it this way
// to play along with how the Context works and thus not expose its internals
req.Context().ConstructNode = func() (*core.IpfsNode, error) {
return core.NewIpfsNode(cfg, true)
return node, nil
}
node, err := req.Context().GetNode()
addr, err := ma.NewMultiaddr(cfg.Addresses.API)
if err != nil {
return nil, err
}
addr, err := ma.NewMultiaddr(cfg.Addresses.API)
_, host, err := manet.DialArgs(addr)
if err != nil {
return nil, err
}
_, host, err := manet.DialArgs(addr)
// mount if the user provided the --mount flag
mount, _, err := req.Option(mountKwd).Bool()
if err != nil {
return nil, err
}
if mount {
fsdir, found, err := req.Option(ipfsMountKwd).String()
if err != nil {
return nil, err
}
if !found {
fsdir = cfg.Mounts.IPFS
}
nsdir, found, err := req.Option(ipnsMountKwd).String()
if err != nil {
return nil, err
}
if !found {
nsdir = cfg.Mounts.IPNS
}
err = commands.Mount(node, fsdir, nsdir)
if err != nil {
return nil, err
}
}
mux := http.NewServeMux()
cmdHandler := cmdsHttp.NewHandler(*req.Context(), commands.Root)
......
......@@ -100,25 +100,11 @@ baz
return nil, err
}
// check if we already have live mounts.
// if the user said "Mount", then there must be something wrong.
// so, close them and try again.
if node.Mounts.Ipfs != nil {
node.Mounts.Ipfs.Unmount()
}
if node.Mounts.Ipns != nil {
node.Mounts.Ipns.Unmount()
}
// error if we aren't running node in online mode
if node.Network == nil {
if !node.OnlineMode() {
return nil, errNotOnline
}
if err := platformFuseChecks(); err != nil {
return nil, err
}
fsdir, found, err := req.Option("f").String()
if err != nil {
return nil, err
......@@ -136,7 +122,8 @@ baz
nsdir = cfg.Mounts.IPNS // NB: be sure to not redeclare!
}
if err := doMount(node, fsdir, nsdir); err != nil {
err = Mount(node, fsdir, nsdir)
if err != nil {
return nil, err
}
......@@ -207,3 +194,26 @@ func doMount(node *core.IpfsNode, fsdir, nsdir string) error {
var platformFuseChecks = func() error {
return nil
}
func Mount(node *core.IpfsNode, fsdir, nsdir string) error {
// check if we already have live mounts.
// if the user said "Mount", then there must be something wrong.
// so, close them and try again.
if node.Mounts.Ipfs != nil {
node.Mounts.Ipfs.Unmount()
}
if node.Mounts.Ipns != nil {
node.Mounts.Ipns.Unmount()
}
if err := platformFuseChecks(); err != nil {
return err
}
var err error
if err = doMount(node, fsdir, nsdir); err != nil {
return err
}
return 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