diff --git a/cmd/ipfs/ipfs.go b/cmd/ipfs/ipfs.go index 34010b010ab494ee26c046560e1e2a3df8567a1c..0e94627f961d7864d6509afe1a74c9fc8b56139b 100644 --- a/cmd/ipfs/ipfs.go +++ b/cmd/ipfs/ipfs.go @@ -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}, } diff --git a/core/commands/commands_test.go b/core/commands/commands_test.go index 23de2ba522589791054741289b4a7f3b05693576..b15dc7677efaf27c64440e91591b250ddbace916 100644 --- a/core/commands/commands_test.go +++ b/core/commands/commands_test.go @@ -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", diff --git a/core/commands/repo.go b/core/commands/repo.go index 8ef3b2719ef3d7ca3bebf78afec09bfc76326089..da8f8a7124ee5b4328ee181bdddd7bf62f09be7a 100644 --- a/core/commands/repo.go +++ b/core/commands/repo.go @@ -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, }, } @@ -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. @@ -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 @@ -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), diff --git a/test/sharness/t0089-repo-rm-files-root.sh b/test/sharness/t0089-repo-rm-files-root.sh new file mode 100755 index 0000000000000000000000000000000000000000..ba7b8f191162a3b429ada1bc553a92a851655ce1 --- /dev/null +++ b/test/sharness/t0089-repo-rm-files-root.sh @@ -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 diff --git a/test/sharness/t0089-repo-rm-root.sh b/test/sharness/t0089-repo-rm-root.sh deleted file mode 100755 index 0dbd4c2a0c5338ec16e084ff5f7ff5f2d7d2b38a..0000000000000000000000000000000000000000 --- a/test/sharness/t0089-repo-rm-root.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/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-root fails without --confirm" ' - test_must_fail ipfs repo rm-root 2> err && - cat err && - fgrep -q "please pass --confirm to proceed" err -' - -test_expect_success "ipfs repo rm-root fails to remove existing root without --remove-existing-root" ' - test_must_fail ipfs repo rm-root --confirm 2> err && - cat err && - fgrep -q "Are you sure you want to unlink this?" err -' - -test_expect_success "ipfs repo rm-root" ' - ipfs repo rm-root --confirm --remove-existing-root | tee rm-root.actual && - echo "Unlinked files API root. Root hash was $ROOT_HASH." > rm-root.expected && - test_cmp rm-root.expected rm-root.actual -' - -test_expect_success "files api root really removed" ' - ipfs repo rm-root --confirm | tee rm-root-post.actual && - echo "Files API root not found." > rm-root-post.expected && - test_cmp rm-root-post.expected rm-root-post.actual -' - -test_launch_ipfs_daemon - -test_expect_success "ipfs repo rm-root does not run on daemon" ' - test_must_fail ipfs repo rm-root --confirm 2> err && - cat err && - fgrep -q "ipfs daemon is running" err -' - -test_kill_ipfs_daemon - -test_done