Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipfs repo version command #2598

Merged
merged 6 commits into from
Jun 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions core/commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ import (
cmds "github.com/ipfs/go-ipfs/commands"
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
config "github.com/ipfs/go-ipfs/repo/config"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
lockfile "github.com/ipfs/go-ipfs/repo/fsrepo/lock"
u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
"io"
"os"
"path/filepath"
)

type RepoVersion struct {
Version string
}

var RepoCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Manipulate the IPFS repo.",
Expand All @@ -22,9 +27,10 @@ var RepoCmd = &cmds.Command{
},

Subcommands: map[string]*cmds.Command{
"gc": repoGcCmd,
"stat": repoStatCmd,
"fsck": RepoFsckCmd,
"gc": repoGcCmd,
"stat": repoStatCmd,
"fsck": RepoFsckCmd,
"version": repoVersionCmd,
},
}

Expand Down Expand Up @@ -109,6 +115,7 @@ set of stored objects and print repo statistics. It outputs to stdout:
NumObjects int Number of objects in the local repo.
RepoPath string The path to the repo being currently used.
RepoSize int Size in bytes that the repo is currently taking.
Version string The repo version.
`,
},
Run: func(req cmds.Request, res cmds.Response) {
Expand Down Expand Up @@ -151,6 +158,7 @@ RepoSize int Size in bytes that the repo is currently taking.
fmt.Fprintf(buf, "RepoSize \t %d\n", stat.RepoSize)
}
fmt.Fprintf(buf, "RepoPath \t %s\n", stat.RepoPath)
fmt.Fprintf(buf, "Version \t %s\n", stat.Version)

return buf, nil
},
Expand Down Expand Up @@ -208,3 +216,41 @@ daemons are running.
cmds.Text: MessageTextMarshaler,
},
}

var repoVersionCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Show the repo version.",
ShortDescription: `
'ipfs repo version' returns the current repo version.
`,
},

Options: []cmds.Option{
cmds.BoolOption("quiet", "q", "Write minimal output."),
},
Run: func(req cmds.Request, res cmds.Response) {
res.SetOutput(&RepoVersion{
Version: fsrepo.RepoVersion,
})
},
Type: RepoVersion{},
Marshalers: cmds.MarshalerMap{
cmds.Text: func(res cmds.Response) (io.Reader, error) {
response := res.Output().(*RepoVersion)

quiet, _, err := res.Request().Option("quiet").Bool()
if err != nil {
return nil, err
}

buf := new(bytes.Buffer)
if quiet {
buf = bytes.NewBufferString(fmt.Sprintf("fs-repo@%s\n", response.Version))
} else {
buf = bytes.NewBufferString(fmt.Sprintf("ipfs repo version fs-repo@%s\n", response.Version))
}
return buf, nil

},
},
}
2 changes: 2 additions & 0 deletions core/corerepo/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Stat struct {
NumObjects uint64
RepoSize uint64 // size in bytes
RepoPath string
Version string
}

func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) {
Expand Down Expand Up @@ -39,5 +40,6 @@ func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) {
NumObjects: count,
RepoSize: usage,
RepoPath: path,
Version: "fs-repo@" + fsrepo.RepoVersion,
}, nil
}
16 changes: 16 additions & 0 deletions test/sharness/t0080-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ test_expect_success "repo stats came out correct" '
grep "RepoPath" repo-stats &&
grep "RepoSize" repo-stats &&
grep "NumObjects" repo-stats
grep "Version" repo-stats
'

test_expect_success "'ipfs repo stat' after adding a file" '
Expand All @@ -244,6 +245,21 @@ test_expect_success "repo stats are updated correctly" '
test $(get_field_num "RepoSize" repo-stats-2) -ge $(get_field_num "RepoSize" repo-stats)
'

test_expect_success "'ipfs repo version' succeeds" '
ipfs repo version > repo-version
'

test_expect_success "repo version came out correct" '
egrep "^ipfs repo version fs-repo@[0-9]" repo-version >/dev/null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may need to be fs-repo@[0-9]+

'

test_expect_success "'ipfs repo version -q' succeeds" '
ipfs repo version -q > repo-version-q
'
test_expect_success "repo version came out correct" '
egrep "^fs-repo@[0-9]" repo-version-q >/dev/null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may need to be fs-repo@[0-9]+

'

test_kill_ipfs_daemon

test_done