@cryptotaxi247 / kubo / commits / c2ed8ad48

remove init -f option, its bad

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Mar 17, 2016 at 17:11 UTC c2ed8ad48f5e85c1de4a9aa8047a2e5e838e6433
3 files changed +9 -28
cmd/ipfs/init.go
+4 -18
@@ -35,7 +35,6 @@ at ~/.ipfs. To change the repo location, set the $IPFS_PATH environment variable
35
36 Options: []cmds.Option{
37 cmds.IntOption("bits", "b", fmt.Sprintf("Number of bits to use in the generated RSA private key (defaults to %d)", nBitsForKeypairDefault)),
38 - cmds.BoolOption("force", "f", "Overwrite existing config (if it exists)."),
38 cmds.BoolOption("empty-repo", "e", "Don't add and pin help files to the local storage."),
39
40 // TODO need to decide whether to expose the override as a file or a
@@ -64,12 +63,6 @@ at ~/.ipfs. To change the repo location, set the $IPFS_PATH environment variable
63 return
64 }
65
67 - force, _, err := req.Option("f").Bool() // if !found, it's okay force == false
68 - if err != nil {
69 - res.SetError(err, cmds.ErrNormal)
70 - return
71 - }
72 -
66 empty, _, err := req.Option("e").Bool() // if !empty, it's okay empty == false
67 if err != nil {
68 res.SetError(err, cmds.ErrNormal)
@@ -86,7 +79,7 @@ at ~/.ipfs. To change the repo location, set the $IPFS_PATH environment variable
79 nBitsForKeypair = nBitsForKeypairDefault
80 }
81
89 - if err := doInit(os.Stdout, req.InvocContext().ConfigRoot, force, empty, nBitsForKeypair); err != nil {
82 + if err := doInit(os.Stdout, req.InvocContext().ConfigRoot, empty, nBitsForKeypair); err != nil {
83 res.SetError(err, cmds.ErrNormal)
84 return
85 }
@@ -95,14 +88,13 @@ at ~/.ipfs. To change the repo location, set the $IPFS_PATH environment variable
88
89 var errRepoExists = errors.New(`ipfs configuration file already exists!
90 Reinitializing would overwrite your keys.
98 -(use -f to force overwrite)
91 `)
92
93 func initWithDefaults(out io.Writer, repoRoot string) error {
102 - return doInit(out, repoRoot, false, false, nBitsForKeypairDefault)
94 + return doInit(out, repoRoot, false, nBitsForKeypairDefault)
95 }
96
105 -func doInit(out io.Writer, repoRoot string, force bool, empty bool, nBitsForKeypair int) error {
97 +func doInit(out io.Writer, repoRoot string, empty bool, nBitsForKeypair int) error {
98 if _, err := fmt.Fprintf(out, "initializing ipfs node at %s\n", repoRoot); err != nil {
99 return err
100 }
@@ -111,7 +103,7 @@ func doInit(out io.Writer, repoRoot string, force bool, empty bool, nBitsForKeyp
103 return err
104 }
105
114 - if fsrepo.IsInitialized(repoRoot) && !force {
106 + if fsrepo.IsInitialized(repoRoot) {
107 return errRepoExists
108 }
109
@@ -120,12 +112,6 @@ func doInit(out io.Writer, repoRoot string, force bool, empty bool, nBitsForKeyp
112 return err
113 }
114
123 - if fsrepo.IsInitialized(repoRoot) {
124 - if err := fsrepo.Remove(repoRoot); err != nil {
125 - return err
126 - }
127 - }
128 -
115 if err := fsrepo.Init(repoRoot, conf); err != nil {
116 return err
117 }
repo/fsrepo/fsrepo.go
-6
@@ -249,12 +249,6 @@ func Init(repoPath string, conf *config.Config) error {
249 return nil
250 }
251
252 -// Remove recursively removes the FSRepo at |path|.
253 -func Remove(repoPath string) error {
254 - repoPath = filepath.Clean(repoPath)
255 - return os.RemoveAll(repoPath)
256 -}
257 -
252 // LockedByOtherProcess returns true if the FSRepo is locked by another
253 // process. If true, then the repo cannot be opened by this process.
254 func LockedByOtherProcess(repoPath string) (bool, error) {
repo/fsrepo/fsrepo_test.go
+5 -4
@@ -3,6 +3,8 @@ package fsrepo
3 import (
4 "bytes"
5 "io/ioutil"
6 + "os"
7 + "path/filepath"
8 "testing"
9
10 datastore "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
@@ -27,10 +29,9 @@ func TestInitIdempotence(t *testing.T) {
29 }
30 }
31
30 -func TestRemove(t *testing.T) {
31 - t.Parallel()
32 - path := testRepoPath("foo", t)
33 - assert.Nil(Remove(path), t, "can remove a repository")
32 +func Remove(repoPath string) error {
33 + repoPath = filepath.Clean(repoPath)
34 + return os.RemoveAll(repoPath)
35 }
36
37 func TestCanManageReposIndependently(t *testing.T) {