Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ipfs/kubo
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 61cde12364ba
Choose a base ref
...
head repository: ipfs/kubo
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9f253dfa7acf
Choose a head ref
  • 3 commits
  • 2 files changed
  • 3 contributors

Commits on Aug 19, 2015

  1. Add --empty-repo option for init (#1559)

    License: MIT
    Signed-off-by: Pavol Rusnak <stick@gk2.sk>
    prusnak committed Aug 19, 2015
    Copy the full SHA
    73e820a View commit details

Commits on Aug 25, 2015

  1. t0020: add test for --empty-repo

    License: MIT
    Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
    chriscool committed Aug 25, 2015
    Copy the full SHA
    872daf8 View commit details

Commits on Aug 28, 2015

  1. Merge pull request #1592 from prusnak/empty-repo

    Add --empty-repo option for init (#1559)
    jbenet committed Aug 28, 2015
    Copy the full SHA
    9f253df View commit details
Showing with 45 additions and 5 deletions.
  1. +14 −5 cmd/ipfs/init.go
  2. +31 −0 test/sharness/t0020-init.sh
19 changes: 14 additions & 5 deletions cmd/ipfs/init.go
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ var initCmd = &cmds.Command{
Options: []cmds.Option{
cmds.IntOption("bits", "b", fmt.Sprintf("Number of bits to use in the generated RSA private key (defaults to %d)", nBitsForKeypairDefault)),
cmds.BoolOption("force", "f", "Overwrite existing config (if it exists)"),
cmds.BoolOption("empty-repo", "e", "Don't add and pin help files to the local storage"),

// TODO need to decide whether to expose the override as a file or a
// directory. That is: should we allow the user to also specify the
@@ -59,6 +60,12 @@ var initCmd = &cmds.Command{
return
}

empty, _, err := req.Option("e").Bool() // if !empty, it's okay empty == false
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

nBitsForKeypair, bitsOptFound, err := req.Option("b").Int()
if err != nil {
res.SetError(err, cmds.ErrNormal)
@@ -69,7 +76,7 @@ var initCmd = &cmds.Command{
nBitsForKeypair = nBitsForKeypairDefault
}

if err := doInit(os.Stdout, req.InvocContext().ConfigRoot, force, nBitsForKeypair); err != nil {
if err := doInit(os.Stdout, req.InvocContext().ConfigRoot, force, empty, nBitsForKeypair); err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
@@ -82,10 +89,10 @@ Reinitializing would overwrite your keys.
`)

func initWithDefaults(out io.Writer, repoRoot string) error {
return doInit(out, repoRoot, false, nBitsForKeypairDefault)
return doInit(out, repoRoot, false, false, nBitsForKeypairDefault)
}

func doInit(out io.Writer, repoRoot string, force bool, nBitsForKeypair int) error {
func doInit(out io.Writer, repoRoot string, force bool, empty bool, nBitsForKeypair int) error {
if _, err := fmt.Fprintf(out, "initializing ipfs node at %s\n", repoRoot); err != nil {
return err
}
@@ -113,8 +120,10 @@ func doInit(out io.Writer, repoRoot string, force bool, nBitsForKeypair int) err
return err
}

if err := addDefaultAssets(out, repoRoot); err != nil {
return err
if !empty {
if err := addDefaultAssets(out, repoRoot); err != nil {
return err
}
}

return initializeIpnsKeyspace(repoRoot)
31 changes: 31 additions & 0 deletions test/sharness/t0020-init.sh
Original file line number Diff line number Diff line change
@@ -75,6 +75,37 @@ test_expect_success "ipfs init output looks good" '
test_cmp expected actual_init
'

test_expect_success "Welcome readme exists" '
ipfs cat /ipfs/$HASH_WELCOME_DOCS/readme
'

test_expect_success "clean up ipfs dir" '
rm -rf "$IPFS_PATH"
'

test_expect_success "'ipfs init --empty-repo' succeeds" '
BITS="1024" &&
ipfs init --bits="$BITS" --empty-repo >actual_init
'

test_expect_success "ipfs peer id looks good" '
PEERID=$(ipfs config Identity.PeerID) &&
echo $PEERID | tr -dC "[:alnum:]" | wc -c | tr -d " " >actual_peerid &&
echo "46" >expected_peerid &&
test_cmp expected_peerid actual_peerid
'

test_expect_success "'ipfs init --empty-repo' output looks good" '
echo "initializing ipfs node at $IPFS_PATH" >expected &&
echo "generating $BITS-bit RSA keypair...done" >>expected &&
echo "peer identity: $PEERID" >>expected &&
test_cmp expected actual_init
'

test_expect_success "Welcome readme doesn't exists" '
test_must_fail ipfs cat /ipfs/$HASH_WELCOME_DOCS/readme
'

test_expect_success "clean up ipfs dir" '
rm -rf "$IPFS_PATH"
'