Skip to content

Commit

Permalink
Merge pull request #2479 from ipfs/feat/no-init-f
Browse files Browse the repository at this point in the history
remove init -f option, its bad
  • Loading branch information
whyrusleeping committed Apr 28, 2016
2 parents e124ee2 + c2ed8ad commit 1b50a9d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 28 deletions.
22 changes: 4 additions & 18 deletions cmd/ipfs/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ at ~/.ipfs. To change the repo location, set the $IPFS_PATH environment variable

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
Expand Down Expand Up @@ -64,12 +63,6 @@ at ~/.ipfs. To change the repo location, set the $IPFS_PATH environment variable
return
}

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

empty, _, err := req.Option("e").Bool() // if !empty, it's okay empty == false
if err != nil {
res.SetError(err, cmds.ErrNormal)
Expand All @@ -86,7 +79,7 @@ at ~/.ipfs. To change the repo location, set the $IPFS_PATH environment variable
nBitsForKeypair = nBitsForKeypairDefault
}

if err := doInit(os.Stdout, req.InvocContext().ConfigRoot, force, empty, nBitsForKeypair); err != nil {
if err := doInit(os.Stdout, req.InvocContext().ConfigRoot, empty, nBitsForKeypair); err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
Expand All @@ -95,14 +88,13 @@ at ~/.ipfs. To change the repo location, set the $IPFS_PATH environment variable

var errRepoExists = errors.New(`ipfs configuration file already exists!
Reinitializing would overwrite your keys.
(use -f to force overwrite)
`)

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

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

if fsrepo.IsInitialized(repoRoot) && !force {
if fsrepo.IsInitialized(repoRoot) {
return errRepoExists
}

Expand All @@ -120,12 +112,6 @@ func doInit(out io.Writer, repoRoot string, force bool, empty bool, nBitsForKeyp
return err
}

if fsrepo.IsInitialized(repoRoot) {
if err := fsrepo.Remove(repoRoot); err != nil {
return err
}
}

if err := fsrepo.Init(repoRoot, conf); err != nil {
return err
}
Expand Down
6 changes: 0 additions & 6 deletions repo/fsrepo/fsrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,6 @@ func Init(repoPath string, conf *config.Config) error {
return nil
}

// Remove recursively removes the FSRepo at |path|.
func Remove(repoPath string) error {
repoPath = filepath.Clean(repoPath)
return os.RemoveAll(repoPath)
}

// LockedByOtherProcess returns true if the FSRepo is locked by another
// process. If true, then the repo cannot be opened by this process.
func LockedByOtherProcess(repoPath string) (bool, error) {
Expand Down
9 changes: 5 additions & 4 deletions repo/fsrepo/fsrepo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package fsrepo
import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"

datastore "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
Expand All @@ -27,10 +29,9 @@ func TestInitIdempotence(t *testing.T) {
}
}

func TestRemove(t *testing.T) {
t.Parallel()
path := testRepoPath("foo", t)
assert.Nil(Remove(path), t, "can remove a repository")
func Remove(repoPath string) error {
repoPath = filepath.Clean(repoPath)
return os.RemoveAll(repoPath)
}

func TestCanManageReposIndependently(t *testing.T) {
Expand Down

0 comments on commit 1b50a9d

Please sign in to comment.