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
Show 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 (
...
@@ -8,36 +8,47 @@ import (
var
cmdIpfsPin
=
&
commander
.
Command
{
var
cmdIpfsPin
=
&
commander
.
Command
{
UsageLine
:
"pin"
,
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."
,
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
Retrieves the object named by <ipfs-path> and stores it locally
on disk.
on disk.
`
,
`
,
Run
:
pinCmd
,
Run
:
pin
Sub
Cmd
,
Flag
:
*
flag
.
NewFlagSet
(
"ipfs-pin"
,
flag
.
ExitOnError
),
Flag
:
*
flag
.
NewFlagSet
(
"ipfs-pin"
,
flag
.
ExitOnError
),
}
}
var
pinCmd
=
makeCommand
(
command
{
var
pin
Sub
Cmd
=
makeCommand
(
command
{
name
:
"pin"
,
name
:
"pin"
,
args
:
1
,
args
:
1
,
flags
:
[]
string
{
"r"
,
"d"
},
flags
:
[]
string
{
"r"
,
"d"
},
cmdFn
:
commands
.
Pin
,
cmdFn
:
commands
.
Pin
,
})
})
var
cmdIpfsUnpin
=
&
commander
.
Command
{
var
cmdIpfs
Sub
Unpin
=
&
commander
.
Command
{
UsageLine
:
"
unpin
"
,
UsageLine
:
"
rm
"
,
Short
:
"unpin an ipfs object from local storage."
,
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
Removes the pin from the given object allowing it to be garbage
collected if needed.
collected if needed.
`
,
`
,
Run
:
unpinCmd
,
Run
:
unpin
Sub
Cmd
,
Flag
:
*
flag
.
NewFlagSet
(
"ipfs-unpin"
,
flag
.
ExitOnError
),
Flag
:
*
flag
.
NewFlagSet
(
"ipfs-unpin"
,
flag
.
ExitOnError
),
}
}
var
unpinCmd
=
makeCommand
(
command
{
var
unpin
Sub
Cmd
=
makeCommand
(
command
{
name
:
"unpin"
,
name
:
"unpin"
,
args
:
1
,
args
:
1
,
flags
:
[]
string
{
"r"
,
"d"
},
flags
:
[]
string
{
"r"
,
"d"
},
...
@@ -45,7 +56,7 @@ var unpinCmd = makeCommand(command{
...
@@ -45,7 +56,7 @@ var unpinCmd = makeCommand(command{
})
})
func
init
()
{
func
init
()
{
cmdIpfsPin
.
Flag
.
Bool
(
"r"
,
false
,
"pin objects recursively"
)
cmdIpfs
Sub
Pin
.
Flag
.
Bool
(
"r"
,
false
,
"pin objects recursively"
)
cmdIpfsPin
.
Flag
.
Int
(
"d"
,
1
,
"recursive depth"
)
cmdIpfs
Sub
Pin
.
Flag
.
Int
(
"d"
,
1
,
"recursive depth"
)
cmdIpfsUnpin
.
Flag
.
Bool
(
"r"
,
false
,
"unpin objects recursively"
)
cmdIpfs
Sub
Unpin
.
Flag
.
Bool
(
"r"
,
false
,
"unpin objects recursively"
)
}
}
pin/pin.go
View file @
6f750572
...
@@ -3,6 +3,8 @@ package pin
...
@@ -3,6 +3,8 @@ package pin
import
(
import
(
//ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
//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"
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"
nsds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/namespace"
"github.com/jbenet/go-ipfs/blocks/set"
"github.com/jbenet/go-ipfs/blocks/set"
...
@@ -22,6 +24,7 @@ type Pinner interface {
...
@@ -22,6 +24,7 @@ type Pinner interface {
}
}
type
pinner
struct
{
type
pinner
struct
{
lock
sync
.
RWMutex
recursePin
set
.
BlockSet
recursePin
set
.
BlockSet
directPin
set
.
BlockSet
directPin
set
.
BlockSet
indirPin
*
indirectPin
indirPin
*
indirectPin
...
@@ -49,6 +52,8 @@ func NewPinner(dstore ds.Datastore, serv *mdag.DAGService) Pinner {
...
@@ -49,6 +52,8 @@ func NewPinner(dstore ds.Datastore, serv *mdag.DAGService) Pinner {
}
}
func
(
p
*
pinner
)
Pin
(
node
*
mdag
.
Node
,
recurse
bool
)
error
{
func
(
p
*
pinner
)
Pin
(
node
*
mdag
.
Node
,
recurse
bool
)
error
{
p
.
lock
.
Lock
()
defer
p
.
lock
.
Unlock
()
k
,
err
:=
node
.
Key
()
k
,
err
:=
node
.
Key
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -72,6 +77,8 @@ func (p *pinner) Pin(node *mdag.Node, recurse bool) error {
...
@@ -72,6 +77,8 @@ func (p *pinner) Pin(node *mdag.Node, recurse bool) error {
}
}
func
(
p
*
pinner
)
Unpin
(
k
util
.
Key
,
recurse
bool
)
error
{
func
(
p
*
pinner
)
Unpin
(
k
util
.
Key
,
recurse
bool
)
error
{
p
.
lock
.
Lock
()
defer
p
.
lock
.
Unlock
()
if
recurse
{
if
recurse
{
p
.
recursePin
.
RemoveBlock
(
k
)
p
.
recursePin
.
RemoveBlock
(
k
)
node
,
err
:=
p
.
dserv
.
Get
(
k
)
node
,
err
:=
p
.
dserv
.
Get
(
k
)
...
@@ -134,6 +141,8 @@ func (p *pinner) pinLinks(node *mdag.Node) error {
...
@@ -134,6 +141,8 @@ func (p *pinner) pinLinks(node *mdag.Node) error {
}
}
func
(
p
*
pinner
)
IsPinned
(
key
util
.
Key
)
bool
{
func
(
p
*
pinner
)
IsPinned
(
key
util
.
Key
)
bool
{
p
.
lock
.
RLock
()
defer
p
.
lock
.
RUnlock
()
return
p
.
recursePin
.
HasKey
(
key
)
||
return
p
.
recursePin
.
HasKey
(
key
)
||
p
.
directPin
.
HasKey
(
key
)
||
p
.
directPin
.
HasKey
(
key
)
||
p
.
indirPin
.
HasKey
(
key
)
p
.
indirPin
.
HasKey
(
key
)
...
@@ -164,6 +173,8 @@ func LoadPinner(d ds.Datastore, dserv *mdag.DAGService) (Pinner, error) {
...
@@ -164,6 +173,8 @@ func LoadPinner(d ds.Datastore, dserv *mdag.DAGService) (Pinner, error) {
}
}
func
(
p
*
pinner
)
Flush
()
error
{
func
(
p
*
pinner
)
Flush
()
error
{
p
.
lock
.
RLock
()
defer
p
.
lock
.
RUnlock
()
recurse
:=
p
.
recursePin
.
GetKeys
()
recurse
:=
p
.
recursePin
.
GetKeys
()
err
:=
p
.
dstore
.
Put
(
recursePinDatastoreKey
,
recurse
)
err
:=
p
.
dstore
.
Put
(
recursePinDatastoreKey
,
recurse
)
if
err
!=
nil
{
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