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
440c90be
Commit
440c90be
authored
Nov 06, 2014
by
Brian Tiger Chow
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extract unpin
@mappum
parent
92d20e42
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
23 deletions
+33
-23
core/commands2/pin.go
core/commands2/pin.go
+33
-23
No files found.
core/commands2/pin.go
View file @
440c90be
package
commands
import
(
"errors"
"fmt"
cmds
"github.com/jbenet/go-ipfs/commands"
"github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/core/commands2/internal"
"github.com/jbenet/go-ipfs/merkledag"
)
...
...
@@ -37,7 +37,7 @@ var pinCmd = &cmds.Command{
}
}*/
paths
,
err
:=
t
oStrings
(
req
.
Arguments
())
paths
,
err
:=
internal
.
T
oStrings
(
req
.
Arguments
())
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
...
...
@@ -66,28 +66,13 @@ var unpinCmd = &cmds.Command{
opt
,
_
:=
req
.
Option
(
"recursive"
)
recursive
,
_
:=
opt
.
(
bool
)
// false if cast fails.
for
_
,
arg
:=
range
req
.
Arguments
()
{
path
,
ok
:=
arg
.
(
string
)
if
!
ok
{
res
.
SetError
(
errors
.
New
(
"cast error"
),
cmds
.
ErrNormal
)
return
}
dagnode
,
err
:=
n
.
Resolver
.
ResolvePath
(
path
)
if
err
!=
nil
{
res
.
SetError
(
fmt
.
Errorf
(
"pin error: %v"
,
err
),
cmds
.
ErrNormal
)
return
}
k
,
_
:=
dagnode
.
Key
()
err
=
n
.
Pinning
.
Unpin
(
k
,
recursive
)
if
err
!=
nil
{
res
.
SetError
(
fmt
.
Errorf
(
"pin: %v"
,
err
),
cmds
.
ErrNormal
)
return
}
paths
,
err
:=
internal
.
ToStrings
(
req
.
Arguments
())
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
err
:
=
n
.
Pinning
.
Flush
(
)
_
,
err
=
unpin
(
n
,
paths
,
recursive
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
}
...
...
@@ -100,7 +85,6 @@ func pin(n *core.IpfsNode, paths []string, recursive bool) ([]*merkledag.Node, e
dagnodes
:=
make
([]
*
merkledag
.
Node
,
0
)
for
_
,
path
:=
range
paths
{
dagnode
,
err
:=
n
.
Resolver
.
ResolvePath
(
path
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"pin error: %v"
,
err
)
...
...
@@ -122,3 +106,29 @@ func pin(n *core.IpfsNode, paths []string, recursive bool) ([]*merkledag.Node, e
return
dagnodes
,
nil
}
func
unpin
(
n
*
core
.
IpfsNode
,
paths
[]
string
,
recursive
bool
)
([]
*
merkledag
.
Node
,
error
)
{
dagnodes
:=
make
([]
*
merkledag
.
Node
,
0
)
for
_
,
path
:=
range
paths
{
dagnode
,
err
:=
n
.
Resolver
.
ResolvePath
(
path
)
if
err
!=
nil
{
return
nil
,
err
}
dagnodes
=
append
(
dagnodes
,
dagnode
)
}
for
_
,
dagnode
:=
range
dagnodes
{
k
,
_
:=
dagnode
.
Key
()
err
:=
n
.
Pinning
.
Unpin
(
k
,
recursive
)
if
err
!=
nil
{
return
nil
,
err
}
}
err
:=
n
.
Pinning
.
Flush
()
if
err
!=
nil
{
return
nil
,
err
}
return
dagnodes
,
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