Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
7a4491ad
Commit
7a4491ad
authored
Nov 18, 2014
by
Matt Bell
Committed by
Juan Batiz-Benet
Nov 18, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added --mount flag to mount when running 'ipfs daemon'
parent
105f2321
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
25 deletions
+69
-25
cmd/ipfs2/daemon.go
cmd/ipfs2/daemon.go
+43
-9
core/commands2/mount_unix.go
core/commands2/mount_unix.go
+26
-16
No files found.
cmd/ipfs2/daemon.go
View file @
7a4491ad
...
...
@@ -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
:=
ma
net
.
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
)
...
...
core/commands2/mount_unix.go
View file @
7a4491ad
...
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment