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
f0781d81
Commit
f0781d81
authored
Jan 14, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial implementation of repo-gc command
parent
99872f61
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
2 deletions
+107
-2
core/commands/mount_unix.go
core/commands/mount_unix.go
+1
-1
core/commands/repo.go
core/commands/repo.go
+104
-0
core/commands/root.go
core/commands/root.go
+2
-1
No files found.
core/commands/mount_unix.go
View file @
f0781d81
...
...
@@ -9,11 +9,11 @@ import (
"time"
cmds
"github.com/jbenet/go-ipfs/commands"
config
"github.com/jbenet/go-ipfs/repo/config"
core
"github.com/jbenet/go-ipfs/core"
ipns
"github.com/jbenet/go-ipfs/fuse/ipns"
mount
"github.com/jbenet/go-ipfs/fuse/mount"
rofs
"github.com/jbenet/go-ipfs/fuse/readonly"
config
"github.com/jbenet/go-ipfs/repo/config"
)
// amount of time to wait for mount errors
...
...
core/commands/repo.go
0 → 100644
View file @
f0781d81
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"
)
var
RepoCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Manipulate the IPFS repo"
,
ShortDescription
:
`
'ipfs repo' is a plumbing command used to manipulate the repo.
`
,
},
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"gc"
:
repoGcCmd
,
},
}
type
KeyRemoved
struct
{
Key
u
.
Key
}
var
repoGcCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Perform a garbage collection sweep on the repo"
,
ShortDescription
:
`
'ipfs repo gc' is a plumbing command that will sweep the local
set of stored objects and remove ones that are not pinned in
order to reclaim hard disk space.
`
,
},
Options
:
[]
cmds
.
Option
{
cmds
.
BoolOption
(
"quiet"
,
"q"
,
"Write minimal output"
),
},
Run
:
func
(
req
cmds
.
Request
)
(
interface
{},
error
)
{
n
,
err
:=
req
.
Context
()
.
GetNode
()
if
err
!=
nil
{
return
nil
,
err
}
keychan
,
err
:=
n
.
Blockstore
.
AllKeysChan
(
req
.
Context
()
.
Context
,
0
,
1
<<
16
)
if
err
!=
nil
{
return
nil
,
err
}
outChan
:=
make
(
chan
interface
{})
go
GarbageCollectBlockstore
(
n
,
keychan
,
outChan
)
return
outChan
,
nil
},
Type
:
KeyRemoved
{},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
outChan
,
ok
:=
res
.
Output
()
.
(
chan
interface
{})
if
!
ok
{
return
nil
,
u
.
ErrCast
()
}
quiet
,
_
,
err
:=
res
.
Request
()
.
Option
(
"quiet"
)
.
Bool
()
if
err
!=
nil
{
return
nil
,
err
}
marshal
:=
func
(
v
interface
{})
(
io
.
Reader
,
error
)
{
obj
,
ok
:=
v
.
(
*
KeyRemoved
)
if
!
ok
{
return
nil
,
u
.
ErrCast
()
}
var
buf
*
bytes
.
Buffer
if
quiet
{
buf
=
bytes
.
NewBufferString
(
string
(
obj
.
Key
)
+
"
\n
"
)
}
else
{
buf
=
bytes
.
NewBufferString
(
fmt
.
Sprintf
(
"removed %s
\n
"
,
obj
.
Key
))
}
return
buf
,
nil
}
return
&
cmds
.
ChannelMarshaler
{
Channel
:
outChan
,
Marshaler
:
marshal
,
},
nil
},
},
}
func
GarbageCollectBlockstore
(
n
*
core
.
IpfsNode
,
keychan
<-
chan
u
.
Key
,
output
chan
interface
{})
{
defer
close
(
output
)
for
k
:=
range
keychan
{
if
!
n
.
Pinning
.
IsPinned
(
k
)
{
err
:=
n
.
Blockstore
.
DeleteBlock
(
k
)
if
err
!=
nil
{
log
.
Errorf
(
"Error removing key from blockstore: %s"
,
err
)
}
output
<-
&
KeyRemoved
{
k
}
}
}
}
core/commands/root.go
View file @
f0781d81
...
...
@@ -79,9 +79,10 @@ var rootSubcommands = map[string]*cmds.Command{
"name"
:
NameCmd
,
"object"
:
ObjectCmd
,
"pin"
:
PinCmd
,
"ping"
:
PingCmd
,
"refs"
:
RefsCmd
,
"repo"
:
RepoCmd
,
"swarm"
:
SwarmCmd
,
"ping"
:
PingCmd
,
"update"
:
UpdateCmd
,
"version"
:
VersionCmd
,
}
...
...
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