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

remove init -f option, its bad #2479

Merged
merged 1 commit into from
Apr 28, 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
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