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
b91db680
Commit
b91db680
authored
Jan 19, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update pinning to new semantics, and fix a couple bugs
parent
3601a93d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
100 additions
and
84 deletions
+100
-84
core/commands/add.go
core/commands/add.go
+5
-0
core/commands/pin.go
core/commands/pin.go
+3
-75
core/commands/repo.go
core/commands/repo.go
+1
-1
core/repo/pinning.go
core/repo/pinning.go
+70
-0
pin/pin.go
pin/pin.go
+19
-6
pin/pin_test.go
pin/pin_test.go
+2
-2
No files found.
core/commands/add.go
View file @
b91db680
...
...
@@ -122,6 +122,11 @@ func add(n *core.IpfsNode, readers []io.Reader) ([]*dag.Node, error) {
dagnodes
=
append
(
dagnodes
,
node
)
}
err
:=
n
.
Pinning
.
Flush
()
if
err
!=
nil
{
return
nil
,
err
}
return
dagnodes
,
nil
}
...
...
core/commands/pin.go
View file @
b91db680
...
...
@@ -6,8 +6,7 @@ import (
"io"
cmds
"github.com/jbenet/go-ipfs/commands"
"github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/merkledag"
corerepo
"github.com/jbenet/go-ipfs/core/repo"
u
"github.com/jbenet/go-ipfs/util"
)
...
...
@@ -58,21 +57,11 @@ on disk.
recursive
=
false
}
no
de
s
,
err
:=
p
in
(
n
,
req
.
Arguments
(),
recursive
)
ad
de
d
,
err
:=
corerepo
.
P
in
(
n
,
req
.
Arguments
(),
recursive
)
if
err
!=
nil
{
return
nil
,
err
}
var
added
[]
u
.
Key
for
_
,
node
:=
range
nodes
{
k
,
err
:=
node
.
Key
()
if
err
!=
nil
{
return
nil
,
err
}
added
=
append
(
added
,
k
)
}
// TODO: create some output to show what got pinned
return
&
PinOutput
{
added
},
nil
},
Marshalers
:
cmds
.
MarshalerMap
{
...
...
@@ -122,20 +111,11 @@ collected if needed.
recursive
=
false
// default
}
nodes
,
err
:=
u
npin
(
n
,
req
.
Arguments
(),
recursive
)
removed
,
err
:=
corerepo
.
U
npin
(
n
,
req
.
Arguments
(),
recursive
)
if
err
!=
nil
{
return
nil
,
err
}
var
removed
[]
u
.
Key
for
_
,
node
:=
range
nodes
{
k
,
err
:=
node
.
Key
()
if
err
!=
nil
{
return
nil
,
err
}
removed
=
append
(
removed
,
k
)
}
return
&
PinOutput
{
removed
},
nil
},
Marshalers
:
cmds
.
MarshalerMap
{
...
...
@@ -215,55 +195,3 @@ Use --type=<type> to specify the type of pinned keys to list. Valid values are:
cmds
.
Text
:
KeyListTextMarshaler
,
},
}
func
pin
(
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
,
fmt
.
Errorf
(
"pin error: %v"
,
err
)
}
dagnodes
=
append
(
dagnodes
,
dagnode
)
}
for
_
,
dagnode
:=
range
dagnodes
{
err
:=
n
.
Pinning
.
Pin
(
dagnode
,
recursive
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"pin: %v"
,
err
)
}
}
err
:=
n
.
Pinning
.
Flush
()
if
err
!=
nil
{
return
nil
,
err
}
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
}
core/commands/repo.go
View file @
b91db680
...
...
@@ -3,10 +3,10 @@ package commands
import
(
"bytes"
"fmt"
"io"
cmds
"github.com/jbenet/go-ipfs/commands"
"github.com/jbenet/go-ipfs/core"
u
"github.com/jbenet/go-ipfs/util"
"io"
)
var
RepoCmd
=
&
cmds
.
Command
{
...
...
core/repo/pinning.go
0 → 100644
View file @
b91db680
package
corerepo
import
(
"fmt"
"github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/merkledag"
u
"github.com/jbenet/go-ipfs/util"
)
func
Pin
(
n
*
core
.
IpfsNode
,
paths
[]
string
,
recursive
bool
)
([]
u
.
Key
,
error
)
{
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
)
}
dagnodes
=
append
(
dagnodes
,
dagnode
)
}
var
out
[]
u
.
Key
for
_
,
dagnode
:=
range
dagnodes
{
k
,
err
:=
dagnode
.
Key
()
if
err
!=
nil
{
return
nil
,
err
}
err
=
n
.
Pinning
.
Pin
(
dagnode
,
recursive
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"pin: %v"
,
err
)
}
out
=
append
(
out
,
k
)
}
err
:=
n
.
Pinning
.
Flush
()
if
err
!=
nil
{
return
nil
,
err
}
return
out
,
nil
}
func
Unpin
(
n
*
core
.
IpfsNode
,
paths
[]
string
,
recursive
bool
)
([]
u
.
Key
,
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
)
}
var
unpinned
[]
u
.
Key
for
_
,
dagnode
:=
range
dagnodes
{
k
,
_
:=
dagnode
.
Key
()
err
:=
n
.
Pinning
.
Unpin
(
k
)
if
err
!=
nil
{
return
nil
,
err
}
unpinned
=
append
(
unpinned
,
k
)
}
err
:=
n
.
Pinning
.
Flush
()
if
err
!=
nil
{
return
nil
,
err
}
return
unpinned
,
nil
}
pin/pin.go
View file @
b91db680
...
...
@@ -25,12 +25,13 @@ const (
Recursive
PinMode
=
iota
Direct
Indirect
NotPinned
)
type
Pinner
interface
{
IsPinned
(
util
.
Key
)
bool
Pin
(
*
mdag
.
Node
,
bool
)
error
Unpin
(
util
.
Key
,
bool
)
error
Unpin
(
util
.
Key
)
error
Flush
()
error
GetManual
()
ManualPinner
DirectKeys
()
[]
util
.
Key
...
...
@@ -90,6 +91,10 @@ func (p *pinner) Pin(node *mdag.Node, recurse bool) error {
return
nil
}
if
p
.
directPin
.
HasKey
(
k
)
{
p
.
directPin
.
RemoveBlock
(
k
)
}
p
.
recursePin
.
AddBlock
(
k
)
err
:=
p
.
pinLinks
(
node
)
...
...
@@ -97,16 +102,19 @@ func (p *pinner) Pin(node *mdag.Node, recurse bool) error {
return
err
}
}
else
{
if
p
.
recursePin
.
HasKey
(
k
)
{
return
errors
.
New
(
"Key already pinned recursively."
)
}
p
.
directPin
.
AddBlock
(
k
)
}
return
nil
}
// Unpin a given key
with optional recursive unpinning
func
(
p
*
pinner
)
Unpin
(
k
util
.
Key
,
recurse
bool
)
error
{
// Unpin a given key
func
(
p
*
pinner
)
Unpin
(
k
util
.
Key
)
error
{
p
.
lock
.
Lock
()
defer
p
.
lock
.
Unlock
()
if
recurse
{
if
p
.
recurse
Pin
.
HasKey
(
k
)
{
p
.
recursePin
.
RemoveBlock
(
k
)
node
,
err
:=
p
.
dserv
.
Get
(
k
)
if
err
!=
nil
{
...
...
@@ -114,9 +122,14 @@ func (p *pinner) Unpin(k util.Key, recurse bool) error {
}
return
p
.
unpinLinks
(
node
)
}
else
if
p
.
directPin
.
HasKey
(
k
)
{
p
.
directPin
.
RemoveBlock
(
k
)
return
nil
}
else
if
p
.
indirPin
.
HasKey
(
k
)
{
return
errors
.
New
(
"Cannot unpin indirectly pinned block."
)
}
else
{
return
errors
.
New
(
"Given key was not pinned."
)
}
p
.
directPin
.
RemoveBlock
(
k
)
return
nil
}
func
(
p
*
pinner
)
unpinLinks
(
node
*
mdag
.
Node
)
error
{
...
...
pin/pin_test.go
View file @
b91db680
...
...
@@ -100,8 +100,8 @@ func TestPinnerBasic(t *testing.T) {
t
.
Fatal
(
"pinned node not found."
)
}
// Test
recursive
unpin
err
=
p
.
Unpin
(
dk
,
true
)
// Test unpin
err
=
p
.
Unpin
(
dk
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
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