Skip to content

Commit

Permalink
cmds(ipfs rm-files-root): improve language around rm-root command
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
  • Loading branch information
Stebalien committed Mar 5, 2019
1 parent dc303d0 commit 784e0d8
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 72 deletions.
20 changes: 10 additions & 10 deletions cmd/ipfs/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ func (d *cmdDetails) usesRepo() bool { return !d.doesNotUseRepo }
// properties so that other code can make decisions about whether to invoke a
// command or return an error to the user.
var cmdDetailsMap = map[string]cmdDetails{
"init": {doesNotUseConfigAsInput: true, cannotRunOnDaemon: true, doesNotUseRepo: true},
"daemon": {doesNotUseConfigAsInput: true, cannotRunOnDaemon: true},
"commands": {doesNotUseRepo: true},
"version": {doesNotUseConfigAsInput: true, doesNotUseRepo: true}, // must be permitted to run before init
"log": {cannotRunOnClient: true},
"diag/cmds": {cannotRunOnClient: true},
"repo/fsck": {cannotRunOnDaemon: true},
"repo/rm-root": {cannotRunOnDaemon: true},
"config/edit": {cannotRunOnDaemon: true, doesNotUseRepo: true},
"cid": {doesNotUseRepo: true},
"init": {doesNotUseConfigAsInput: true, cannotRunOnDaemon: true, doesNotUseRepo: true},
"daemon": {doesNotUseConfigAsInput: true, cannotRunOnDaemon: true},
"commands": {doesNotUseRepo: true},
"version": {doesNotUseConfigAsInput: true, doesNotUseRepo: true}, // must be permitted to run before init
"log": {cannotRunOnClient: true},
"diag/cmds": {cannotRunOnClient: true},
"repo/fsck": {cannotRunOnDaemon: true},
"repo/rm-files-root": {cannotRunOnDaemon: true},
"config/edit": {cannotRunOnDaemon: true, doesNotUseRepo: true},
"cid": {doesNotUseRepo: true},
}
2 changes: 1 addition & 1 deletion core/commands/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestCommands(t *testing.T) {
"/repo/stat",
"/repo/verify",
"/repo/version",
"/repo/rm-root",
"/repo/rm-files-root",
"/resolve",
"/shutdown",
"/stats",
Expand Down
24 changes: 12 additions & 12 deletions core/commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ var RepoCmd = &cmds.Command{
},

Subcommands: map[string]*cmds.Command{
"stat": repoStatCmd,
"gc": repoGcCmd,
"fsck": repoFsckCmd,
"version": repoVersionCmd,
"verify": repoVerifyCmd,
"rm-root": repoRmRootCmd,
"stat": repoStatCmd,
"gc": repoGcCmd,
"fsck": repoFsckCmd,
"version": repoVersionCmd,
"verify": repoVerifyCmd,
"rm-files-root": repoRmFilesRootCmd,
},
}

Expand Down Expand Up @@ -266,11 +266,11 @@ daemons are running.
},
}

var repoRmRootCmd = &cmds.Command{
var repoRmFilesRootCmd = &cmds.Command{
Helptext: cmdkit.HelpText{
Tagline: "Unlink the root used by the files API.",
Tagline: "Unlink the root used by the `ipfs files` comands.",
ShortDescription: `
'ipfs repo rm-root' will unlink the root used by the files API ('ipfs
'ipfs repo rm-files-root' will unlink the root used by the files API ('ipfs
files' commands) without trying to read the root itself. The root and
its children will be removed the next time the garbage collector runs,
unless pinned.
Expand Down Expand Up @@ -315,7 +315,7 @@ This command can only run when the ipfs daemon is not running.
// such as pin it
val, err := repo.Datastore().Get(core.FilesRootKey)
if err == ds.ErrNotFound || val == nil {
return cmds.EmitOnce(res, &MessageOutput{"Files API root not found.\n"})
return cmds.EmitOnce(res, &MessageOutput{"`ipfs files` root not found.\n"})
}

var cidStr string
Expand All @@ -329,12 +329,12 @@ This command can only run when the ipfs daemon is not running.
}

if have && !removeExistingRoot {
return fmt.Errorf("root %s exists locally. Are you sure you want to unlink this? Pass --remove-existing-root to continue", cidStr)
return fmt.Errorf("`ipfs files` root %s exists locally. Are you sure you want to unlink this? Pass --remove-existing-root to continue", cidStr)
}

err = repo.Datastore().Delete(core.FilesRootKey)
if err != nil {
return fmt.Errorf("unable to remove API root: %s. Root hash was %s", err.Error(), cidStr)
return fmt.Errorf("unable to remove `ipfs files` root: %s. Root hash was %s", err.Error(), cidStr)
}
return cmds.EmitOnce(res, &MessageOutput{
fmt.Sprintf("Unlinked files API root. Root hash was %s.\n", cidStr),
Expand Down
49 changes: 49 additions & 0 deletions test/sharness/t0089-repo-rm-files-root.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
#
# Copyright (c) 2016 Jeromy Johnson
# MIT Licensed; see the LICENSE file in this repository.
#

test_description="Test ipfs repo fsck"

. lib/test-lib.sh

test_init_ipfs

ROOT_HASH=QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn

test_expect_success "ipfs repo rm-files-root fails without --confirm" '
test_must_fail ipfs repo rm-files-root 2> err &&
cat err &&
fgrep -q "please pass --confirm to proceed" err
'

test_expect_success "ipfs repo rm-files-root fails to remove existing root without --remove-existing-root" '
test_must_fail ipfs repo rm-files-root --confirm 2> err &&
cat err &&
fgrep -q "Are you sure you want to unlink this?" err
'

test_expect_success "ipfs repo rm-files-root" '
ipfs repo rm-files-root --confirm --remove-existing-root | tee rm-files-root.actual &&
echo "Unlinked files API root. Root hash was $ROOT_HASH." > rm-files-root.expected &&
test_cmp rm-files-root.expected rm-files-root.actual
'

test_expect_success "files api root really removed" '
ipfs repo rm-files-root --confirm | tee rm-files-root-post.actual &&
echo "Files API root not found." > rm-files-root-post.expected &&
test_cmp rm-files-root-post.expected rm-files-root-post.actual
'

test_launch_ipfs_daemon

test_expect_success "ipfs repo rm-files-root does not run on daemon" '
test_must_fail ipfs repo rm-files-root --confirm 2> err &&
cat err &&
fgrep -q "ipfs daemon is running" err
'

test_kill_ipfs_daemon

test_done
49 changes: 0 additions & 49 deletions test/sharness/t0089-repo-rm-root.sh

This file was deleted.

0 comments on commit 784e0d8

Please sign in to comment.