mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-03 04:37:30 +08:00
Merge pull request #2598 from pfista/2571-repo-version
`ipfs repo version` command
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
|||||||
cmds "github.com/ipfs/go-ipfs/commands"
|
cmds "github.com/ipfs/go-ipfs/commands"
|
||||||
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
|
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
|
||||||
config "github.com/ipfs/go-ipfs/repo/config"
|
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"
|
lockfile "github.com/ipfs/go-ipfs/repo/fsrepo/lock"
|
||||||
u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
|
u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
|
||||||
"io"
|
"io"
|
||||||
@ -13,6 +14,10 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type RepoVersion struct {
|
||||||
|
Version string
|
||||||
|
}
|
||||||
|
|
||||||
var RepoCmd = &cmds.Command{
|
var RepoCmd = &cmds.Command{
|
||||||
Helptext: cmds.HelpText{
|
Helptext: cmds.HelpText{
|
||||||
Tagline: "Manipulate the IPFS repo.",
|
Tagline: "Manipulate the IPFS repo.",
|
||||||
@ -22,9 +27,10 @@ var RepoCmd = &cmds.Command{
|
|||||||
},
|
},
|
||||||
|
|
||||||
Subcommands: map[string]*cmds.Command{
|
Subcommands: map[string]*cmds.Command{
|
||||||
"gc": repoGcCmd,
|
"gc": repoGcCmd,
|
||||||
"stat": repoStatCmd,
|
"stat": repoStatCmd,
|
||||||
"fsck": RepoFsckCmd,
|
"fsck": RepoFsckCmd,
|
||||||
|
"version": repoVersionCmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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.
|
NumObjects int Number of objects in the local repo.
|
||||||
RepoPath string The path to the repo being currently used.
|
RepoPath string The path to the repo being currently used.
|
||||||
RepoSize int Size in bytes that the repo is currently taking.
|
RepoSize int Size in bytes that the repo is currently taking.
|
||||||
|
Version string The repo version.
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
Run: func(req cmds.Request, res cmds.Response) {
|
Run: func(req cmds.Request, res cmds.Response) {
|
||||||
@ -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, "RepoSize \t %d\n", stat.RepoSize)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(buf, "RepoPath \t %s\n", stat.RepoPath)
|
fmt.Fprintf(buf, "RepoPath \t %s\n", stat.RepoPath)
|
||||||
|
fmt.Fprintf(buf, "Version \t %s\n", stat.Version)
|
||||||
|
|
||||||
return buf, nil
|
return buf, nil
|
||||||
},
|
},
|
||||||
@ -208,3 +216,41 @@ daemons are running.
|
|||||||
cmds.Text: MessageTextMarshaler,
|
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
|
||||||
|
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
@ -10,6 +10,7 @@ type Stat struct {
|
|||||||
NumObjects uint64
|
NumObjects uint64
|
||||||
RepoSize uint64 // size in bytes
|
RepoSize uint64 // size in bytes
|
||||||
RepoPath string
|
RepoPath string
|
||||||
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) {
|
func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) {
|
||||||
@ -39,5 +40,6 @@ func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) {
|
|||||||
NumObjects: count,
|
NumObjects: count,
|
||||||
RepoSize: usage,
|
RepoSize: usage,
|
||||||
RepoPath: path,
|
RepoPath: path,
|
||||||
|
Version: "fs-repo@" + fsrepo.RepoVersion,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -233,6 +233,7 @@ test_expect_success "repo stats came out correct" '
|
|||||||
grep "RepoPath" repo-stats &&
|
grep "RepoPath" repo-stats &&
|
||||||
grep "RepoSize" repo-stats &&
|
grep "RepoSize" repo-stats &&
|
||||||
grep "NumObjects" repo-stats
|
grep "NumObjects" repo-stats
|
||||||
|
grep "Version" repo-stats
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success "'ipfs repo stat' after adding a file" '
|
test_expect_success "'ipfs repo stat' after adding a file" '
|
||||||
@ -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 $(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
|
||||||
|
'
|
||||||
|
|
||||||
|
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
|
||||||
|
'
|
||||||
|
|
||||||
test_kill_ipfs_daemon
|
test_kill_ipfs_daemon
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Reference in New Issue
Block a user