mount_unix.go 1.69 KB
Newer Older
1
// +build linux darwin freebsd
2

3 4 5
package main

import (
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
6
	"errors"
7
	"fmt"
8

9 10
	"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
	"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
11 12
	ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"

13
	"github.com/jbenet/go-ipfs/daemon"
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
	rofs "github.com/jbenet/go-ipfs/fuse/readonly"
	u "github.com/jbenet/go-ipfs/util"
)

var cmdIpfsMount = &commander.Command{
	UsageLine: "mount",
	Short:     "Mount an ipfs read-only mountpoint.",
	Long: `ipfs mount <os-path> - Mount an ipfs read-only mountpoint.

    Mount ipfs at a read-only mountpoint on the OS. All ipfs objects
    will be accessible under that directory. Note that the root will
    not be listable, as it is virtual. Accessing known paths directly.

`,
	Run:  mountCmd,
	Flag: *flag.NewFlagSet("ipfs-mount", flag.ExitOnError),
}

func mountCmd(c *commander.Command, inp []string) error {
	if len(inp) < 1 || len(inp[0]) == 0 {
		u.POut(c.Long)
		return nil
	}

38 39
	conf, err := getConfigDir(c.Parent)
	if err != nil {
40
		fmt.Println("Couldnt get config dir")
41 42
		return err
	}
Jeromy's avatar
Jeromy committed
43
	n, err := localNode(conf, true)
44
	if err != nil {
45
		fmt.Println("Local node creation failed.")
46 47 48
		return err
	}

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
49 50
	// launch the API RPC endpoint.
	if n.Config.Addresses.API == "" {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
51 52 53
		return errors.New("no config.RPCAddress endpoint supplied")
	}

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
54
	maddr, err := ma.NewMultiaddr(n.Config.Addresses.API)
55 56 57 58
	if err != nil {
		return err
	}

59
	dl, err := daemon.NewDaemonListener(n, maddr, conf)
60
	if err != nil {
61
		fmt.Println("Failed to create daemon listener.")
62 63 64 65 66
		return err
	}
	go dl.Listen()
	defer dl.Close()

67 68
	mp := inp[0]
	fmt.Printf("Mounting at %s\n", mp)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
69
	return rofs.Mount(n, mp)
70
}