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
6f750572
Commit
6f750572
authored
Oct 20, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add lock to pinner and rework cli
parent
31b0ff03
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
11 deletions
+33
-11
cmd/ipfs/pin.go
cmd/ipfs/pin.go
+22
-11
pin/pin.go
pin/pin.go
+11
-0
No files found.
cmd/ipfs/pin.go
View file @
6f750572
...
...
@@ -8,36 +8,47 @@ import (
var
cmdIpfsPin
=
&
commander
.
Command
{
UsageLine
:
"pin"
,
Short
:
""
,
Long
:
`ipfs pin [add|rm] - object pinning commands
`
,
Subcommands
:
[]
*
commander
.
Command
{
cmdIpfsSubPin
,
cmdIpfsSubUnpin
,
},
}
var
cmdIpfsSubPin
=
&
commander
.
Command
{
UsageLine
:
"add"
,
Short
:
"pin an ipfs object to local storage."
,
Long
:
`ipfs pin <ipfs-path> - pin ipfs object to local storage.
Long
:
`ipfs pin
add
<ipfs-path> - pin ipfs object to local storage.
Retrieves the object named by <ipfs-path> and stores it locally
on disk.
`
,
Run
:
pinCmd
,
Run
:
pin
Sub
Cmd
,
Flag
:
*
flag
.
NewFlagSet
(
"ipfs-pin"
,
flag
.
ExitOnError
),
}
var
pinCmd
=
makeCommand
(
command
{
var
pin
Sub
Cmd
=
makeCommand
(
command
{
name
:
"pin"
,
args
:
1
,
flags
:
[]
string
{
"r"
,
"d"
},
cmdFn
:
commands
.
Pin
,
})
var
cmdIpfsUnpin
=
&
commander
.
Command
{
UsageLine
:
"
unpin
"
,
var
cmdIpfs
Sub
Unpin
=
&
commander
.
Command
{
UsageLine
:
"
rm
"
,
Short
:
"unpin an ipfs object from local storage."
,
Long
:
`ipfs
un
pin <ipfs-path> - unpin ipfs object from local storage.
Long
:
`ipfs pin
rm
<ipfs-path> - unpin ipfs object from local storage.
Removes the pin from the given object allowing it to be garbage
collected if needed.
`
,
Run
:
unpinCmd
,
Run
:
unpin
Sub
Cmd
,
Flag
:
*
flag
.
NewFlagSet
(
"ipfs-unpin"
,
flag
.
ExitOnError
),
}
var
unpinCmd
=
makeCommand
(
command
{
var
unpin
Sub
Cmd
=
makeCommand
(
command
{
name
:
"unpin"
,
args
:
1
,
flags
:
[]
string
{
"r"
,
"d"
},
...
...
@@ -45,7 +56,7 @@ var unpinCmd = makeCommand(command{
})
func
init
()
{
cmdIpfsPin
.
Flag
.
Bool
(
"r"
,
false
,
"pin objects recursively"
)
cmdIpfsPin
.
Flag
.
Int
(
"d"
,
1
,
"recursive depth"
)
cmdIpfsUnpin
.
Flag
.
Bool
(
"r"
,
false
,
"unpin objects recursively"
)
cmdIpfs
Sub
Pin
.
Flag
.
Bool
(
"r"
,
false
,
"pin objects recursively"
)
cmdIpfs
Sub
Pin
.
Flag
.
Int
(
"d"
,
1
,
"recursive depth"
)
cmdIpfs
Sub
Unpin
.
Flag
.
Bool
(
"r"
,
false
,
"unpin objects recursively"
)
}
pin/pin.go
View file @
6f750572
...
...
@@ -3,6 +3,8 @@ package pin
import
(
//ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
"sync"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
nsds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/namespace"
"github.com/jbenet/go-ipfs/blocks/set"
...
...
@@ -22,6 +24,7 @@ type Pinner interface {
}
type
pinner
struct
{
lock
sync
.
RWMutex
recursePin
set
.
BlockSet
directPin
set
.
BlockSet
indirPin
*
indirectPin
...
...
@@ -49,6 +52,8 @@ func NewPinner(dstore ds.Datastore, serv *mdag.DAGService) Pinner {
}
func
(
p
*
pinner
)
Pin
(
node
*
mdag
.
Node
,
recurse
bool
)
error
{
p
.
lock
.
Lock
()
defer
p
.
lock
.
Unlock
()
k
,
err
:=
node
.
Key
()
if
err
!=
nil
{
return
err
...
...
@@ -72,6 +77,8 @@ func (p *pinner) Pin(node *mdag.Node, recurse bool) error {
}
func
(
p
*
pinner
)
Unpin
(
k
util
.
Key
,
recurse
bool
)
error
{
p
.
lock
.
Lock
()
defer
p
.
lock
.
Unlock
()
if
recurse
{
p
.
recursePin
.
RemoveBlock
(
k
)
node
,
err
:=
p
.
dserv
.
Get
(
k
)
...
...
@@ -134,6 +141,8 @@ func (p *pinner) pinLinks(node *mdag.Node) error {
}
func
(
p
*
pinner
)
IsPinned
(
key
util
.
Key
)
bool
{
p
.
lock
.
RLock
()
defer
p
.
lock
.
RUnlock
()
return
p
.
recursePin
.
HasKey
(
key
)
||
p
.
directPin
.
HasKey
(
key
)
||
p
.
indirPin
.
HasKey
(
key
)
...
...
@@ -164,6 +173,8 @@ func LoadPinner(d ds.Datastore, dserv *mdag.DAGService) (Pinner, error) {
}
func
(
p
*
pinner
)
Flush
()
error
{
p
.
lock
.
RLock
()
defer
p
.
lock
.
RUnlock
()
recurse
:=
p
.
recursePin
.
GetKeys
()
err
:=
p
.
dstore
.
Put
(
recursePinDatastoreKey
,
recurse
)
if
err
!=
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