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-dms3
Commits
728f17d3
Commit
728f17d3
authored
Oct 01, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/ipfs/pin.go now uses MakeCommand
+ added recursive pinning func
parent
26a481a9
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
32 deletions
+20
-32
cmd/ipfs/pin.go
cmd/ipfs/pin.go
+4
-28
core/commands/add.go
core/commands/add.go
+1
-1
core/commands/pin.go
core/commands/pin.go
+8
-1
core/core.go
core/core.go
+7
-2
No files found.
cmd/ipfs/pin.go
View file @
728f17d3
package
main
import
(
"os"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
"github.com/jbenet/go-ipfs/core/commands"
"github.com/jbenet/go-ipfs/daemon"
u
"github.com/jbenet/go-ipfs/util"
)
var
cmdIpfsPin
=
&
commander
.
Command
{
...
...
@@ -22,28 +18,8 @@ var cmdIpfsPin = &commander.Command{
Flag
:
*
flag
.
NewFlagSet
(
"ipfs-pin"
,
flag
.
ExitOnError
),
}
func
pinCmd
(
c
*
commander
.
Command
,
inp
[]
string
)
error
{
if
len
(
inp
)
<
1
{
u
.
POut
(
c
.
Long
)
return
nil
}
cmd
:=
daemon
.
NewCommand
()
cmd
.
Command
=
"pin"
cmd
.
Args
=
inp
err
:=
daemon
.
SendCommand
(
cmd
,
"localhost:12345"
)
if
err
!=
nil
{
conf
,
err
:=
getConfigDir
(
c
.
Parent
)
if
err
!=
nil
{
return
err
}
n
,
err
:=
localNode
(
conf
,
false
)
if
err
!=
nil
{
return
err
}
return
commands
.
Pin
(
n
,
cmd
.
Args
,
cmd
.
Opts
,
os
.
Stdout
)
}
return
nil
func
init
()
{
cmdIpfsPin
.
Flag
.
Bool
(
"r"
,
false
,
"pin objects recursively"
)
}
var
pinCmd
=
MakeCommand
(
"pin"
,
[]
string
{
"r"
},
commands
.
Pin
)
core/commands/add.go
View file @
728f17d3
...
...
@@ -133,5 +133,5 @@ func addNode(n *core.IpfsNode, nd *dag.Node, fpath string) error {
u
.
POut
(
"added %s %s
\n
"
,
k
.
Pretty
(),
fpath
)
// ensure we keep it. atm no-op
return
n
.
PinDagNode
(
nd
)
return
n
.
PinDagNode
Recursively
(
nd
,
-
1
)
}
core/commands/pin.go
View file @
728f17d3
...
...
@@ -8,13 +8,20 @@ import (
)
func
Pin
(
n
*
core
.
IpfsNode
,
args
[]
string
,
opts
map
[
string
]
interface
{},
out
io
.
Writer
)
error
{
// if recursive, set flag
depth
:=
1
if
r
,
ok
:=
opts
[
"r"
]
.
(
bool
);
r
&&
ok
{
depth
=
-
1
}
for
_
,
fn
:=
range
args
{
dagnode
,
err
:=
n
.
Resolver
.
ResolvePath
(
fn
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"pin error: %v"
,
err
)
}
err
=
n
.
PinDagNode
(
dagnode
)
err
=
n
.
PinDagNode
Recursively
(
dagnode
,
depth
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"pin: %v"
,
err
)
}
...
...
core/core.go
View file @
728f17d3
...
...
@@ -240,8 +240,13 @@ func initConnections(ctx context.Context, cfg *config.Config, pstore peer.Peerst
}
}
// PinDagNode ensures a given node is stored persistently locally
.
// PinDagNode ensures a given node is stored persistently locally
func
(
n
*
IpfsNode
)
PinDagNode
(
nd
*
merkledag
.
Node
)
error
{
u
.
DOut
(
"Pinning node. Currently No-Op
\n
"
)
return
n
.
PinDagNodeRecursively
(
nd
,
1
)
}
// PinDagNodeRecursively ensures a given node is stored persistently locally
func
(
n
*
IpfsNode
)
PinDagNodeRecursively
(
nd
*
merkledag
.
Node
,
depth
int
)
error
{
u
.
DOut
(
"Pinning node recursively. Currently No-Op
\n
"
)
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