diff --git a/core/commands/repo.go b/core/commands/repo.go index 7d6b8a499a1..cef056c1961 100644 --- a/core/commands/repo.go +++ b/core/commands/repo.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "os" - "path/filepath" "runtime" "strings" "sync" @@ -20,7 +19,6 @@ import ( cid "github.com/ipfs/go-cid" bstore "github.com/ipfs/go-ipfs-blockstore" cmds "github.com/ipfs/go-ipfs-cmds" - config "github.com/ipfs/go-ipfs-config" ) type RepoVersion struct { @@ -216,44 +214,11 @@ var repoFsckCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "Remove repo lockfiles.", ShortDescription: ` -'ipfs repo fsck' is a plumbing command that will remove repo and level db -lockfiles, as well as the api file. This command can only run when no ipfs -daemons are running. +'ipfs repo fsck' is now a no-op. `, }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { - configRoot, err := cmdenv.GetConfigRoot(env) - if err != nil { - return err - } - - dsPath, err := config.DataStorePath(configRoot) - if err != nil { - return err - } - - dsLockFile := filepath.Join(dsPath, "LOCK") // TODO: get this lockfile programmatically - repoLockFile := filepath.Join(configRoot, fsrepo.LockFile) - apiFile := filepath.Join(configRoot, "api") // TODO: get this programmatically - - log.Infof("Removing repo lockfile: %s", repoLockFile) - log.Infof("Removing datastore lockfile: %s", dsLockFile) - log.Infof("Removing api file: %s", apiFile) - - err = os.Remove(repoLockFile) - if err != nil && !os.IsNotExist(err) { - return err - } - err = os.Remove(dsLockFile) - if err != nil && !os.IsNotExist(err) { - return err - } - err = os.Remove(apiFile) - if err != nil && !os.IsNotExist(err) { - return err - } - - return cmds.EmitOnce(res, &MessageOutput{"Lockfiles have been removed.\n"}) + return cmds.EmitOnce(res, &MessageOutput{"`ipfs repo fsck` is deprecated and does nothing.\n"}) }, Type: MessageOutput{}, Encoders: cmds.EncoderMap{ diff --git a/test/sharness/t0083-repo-fsck.sh b/test/sharness/t0083-repo-fsck.sh deleted file mode 100755 index fe567840cd5..00000000000 --- a/test/sharness/t0083-repo-fsck.sh +++ /dev/null @@ -1,190 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2016 Mike Pfister -# MIT Licensed; see the LICENSE file in this repository. -# - -test_description="Test ipfs repo fsck operations" - -. lib/test-lib.sh - -test_init_ipfs - -############################# -# Test without daemon running -############################# -# NOTE: if api file isn't present we can assume the daemon isn't running - -# Try with all lock files present: repo.lock, api, and datastore/LOCK with -# repo.lock and datastore/LOCK being empty -test_expect_success "'ipfs repo fsck' succeeds with no daemon running empty -repo.lock" ' - mkdir -p $IPFS_PATH && - mkdir -p $IPFS_PATH/datastore && - touch $IPFS_PATH/datastore/LOCK && - touch $IPFS_PATH/repo.lock && - printf "/ip4/127.0.0.1/tcp/5001" > "$IPFS_PATH/api" && - ipfs repo fsck > fsck_out_actual1 -' -test_expect_success "'ipfs repo fsck' output looks good with no daemon" ' - grep "Lockfiles have been removed." fsck_out_actual1 -' - -# Make sure the files are actually removed -test_expect_success "'ipfs repo fsck' confirm file deletion" ' - test ! -e "$IPFS_PATH/repo.lock" && - test ! -e "$IPFS_PATH/datastore/LOCK" && - test ! -e "$IPFS_PATH/api" -' - -# Try with all lock files present: repo.lock, api, and datastore/LOCK with -# repo.lock is non-zero TODO: this test is broken until we find consensus on the -# non-zero repo.lock issue -test_expect_success "'ipfs repo fsck' succeeds with no daemon running non-zero -repo.lock" ' - mkdir -p "$IPFS_PATH" && - printf ":D" > "$IPFS_PATH/repo.lock" && - touch "$IPFS_PATH/datastore/LOCK" && - ipfs repo fsck > fsck_out_actual1b -' -test_expect_success "'ipfs repo fsck' output looks good with no daemon" ' - grep "Lockfiles have been removed." fsck_out_actual1b -' - -# Make sure the files are actually removed -test_expect_success "'ipfs repo fsck' confirm file deletion" ' - test ! -e "$IPFS_PATH/repo.lock" && - test ! -e "$IPFS_PATH/datastore/LOCK" && - test ! -e "$IPFS_PATH/api" -' - -######################## -# Test for partial locks -######################## - -# Try with locks api and datastore/LOCK -test_expect_success "'ipfs repo fsck' succeeds partial lock" ' - printf "/ip4/127.0.0.1/tcp/5001" > "$IPFS_PATH/api" && - touch $IPFS_PATH/datastore/LOCK && - ipfs repo fsck > fsck_out_actual2 -' - -test_expect_success "'ipfs repo fsck' output looks good with no daemon" ' - grep "Lockfiles have been removed." fsck_out_actual2 -' - -# Make sure the files are actually removed -test_expect_success "'ipfs repo fsck' confirm file deletion" ' - test ! -e "$IPFS_PATH/repo.lock" && - test ! -e "$IPFS_PATH/datastore/LOCK" && - test ! -e "$IPFS_PATH/api" -' - -# Try with locks api and repo.lock -test_expect_success "'ipfs repo fsck' succeeds partial lock" ' - printf "/ip4/127.0.0.1/tcp/5001" > "$IPFS_PATH/api" && - touch $IPFS_PATH/repo.lock && - ipfs repo fsck > fsck_out_actual3 -' - -test_expect_success "'ipfs repo fsck' output looks good with no daemon" ' - grep "Lockfiles have been removed." fsck_out_actual3 -' - -# Make sure the files are actually removed -test_expect_success "'ipfs repo fsck' confirm file deletion" ' - test ! -e "$IPFS_PATH/repo.lock" && - test ! -e "$IPFS_PATH/datastore/LOCK" && - test ! -e "$IPFS_PATH/api" -' - -# Try with locks repo.lock and datastore -test_expect_success "'ipfs repo fsck' succeeds partial lock" ' - touch $IPFS_PATH/repo.lock && - touch $IPFS_PATH/datastore/LOCK && - ipfs repo fsck > fsck_out_actual4 -' - -test_expect_success "'ipfs repo fsck' output looks good with no daemon" ' - grep "Lockfiles have been removed." fsck_out_actual4 -' - -# Make sure the files are actually removed -test_expect_success "'ipfs repo fsck' confirm file deletion" ' - test ! -e "$IPFS_PATH/repo.lock" && - test ! -e "$IPFS_PATH/datastore/LOCK" && - test ! -e "$IPFS_PATH/api" -' - -####################### -# Test for single locks -####################### - -# Try with single locks repo.lock -test_expect_success "'ipfs repo fsck' succeeds partial lock" ' - touch $IPFS_PATH/repo.lock && - ipfs repo fsck > fsck_out_actual5 -' -test_expect_success "'ipfs repo fsck' output looks good with no daemon" ' - grep "Lockfiles have been removed." fsck_out_actual5 -' - -# Make sure the files are actually removed -test_expect_success "'ipfs repo fsck' confirm file deletion" ' - test ! -e "$IPFS_PATH/repo.lock" && - test ! -e "$IPFS_PATH/datastore/LOCK" && - test ! -e "$IPFS_PATH/api" -' - -# Try with single locks datastore/LOCK -test_expect_success "'ipfs repo fsck' succeeds partial lock" ' - touch $IPFS_PATH/datastore/LOCK && - ipfs repo fsck > fsck_out_actual6 -' -test_expect_success "'ipfs repo fsck' output looks good with no daemon" ' - grep "Lockfiles have been removed." fsck_out_actual6 -' - -# Make sure the files are actually removed -test_expect_success "'ipfs repo fsck' confirm file deletion" ' - test ! -e "$IPFS_PATH/repo.lock" && - test ! -e "$IPFS_PATH/datastore/LOCK" && - test ! -e "$IPFS_PATH/api" -' - -# Try with single lock api -test_expect_success "'ipfs repo fsck' succeeds partial lock" ' - printf "/ip4/127.0.0.1/tcp/5001" > "$IPFS_PATH/api" && - ipfs repo fsck > fsck_out_actual7 -' - -test_expect_success "'ipfs repo fsck' output looks good with no daemon" ' - grep "Lockfiles have been removed." fsck_out_actual7 -' - -# Make sure the files are actually removed -test_expect_success "'ipfs repo fsck' confirm file deletion" ' - test ! -e "$IPFS_PATH/repo.lock" && - test ! -e "$IPFS_PATH/datastore/LOCK" && - test ! -e "$IPFS_PATH/api" -' - -########################## -# Test with daemon running -########################## - -test_launch_ipfs_daemon - -# Daemon is running -> command doesn't run -test_expect_success "'ipfs repo fsck' fails with daemon running" ' - ! (ipfs repo fsck 2>fsck_out_actual8 ) - -' - -test_expect_success "'ipfs repo fsck' output looks good with daemon" ' - grep "Error: ipfs daemon is running" fsck_out_actual8 -' - -test_kill_ipfs_daemon - -test_done