提交 288a83ce 作者: Steven Allen

feat: deprecate ipfs repo fsck command

This command is no longer necessary and is quite dangerous:

1. All lockfiles are now released by the OS when the daemon stops.
2. The API file is ignored when (a) the repo is initialized and (b) daemon is
off.

fixes #6435
上级 e96416de
...@@ -6,7 +6,6 @@ import ( ...@@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"path/filepath"
"runtime" "runtime"
"strings" "strings"
"sync" "sync"
...@@ -20,7 +19,6 @@ import ( ...@@ -20,7 +19,6 @@ import (
cid "github.com/ipfs/go-cid" cid "github.com/ipfs/go-cid"
bstore "github.com/ipfs/go-ipfs-blockstore" bstore "github.com/ipfs/go-ipfs-blockstore"
cmds "github.com/ipfs/go-ipfs-cmds" cmds "github.com/ipfs/go-ipfs-cmds"
config "github.com/ipfs/go-ipfs-config"
) )
type RepoVersion struct { type RepoVersion struct {
...@@ -216,44 +214,11 @@ var repoFsckCmd = &cmds.Command{ ...@@ -216,44 +214,11 @@ var repoFsckCmd = &cmds.Command{
Helptext: cmds.HelpText{ Helptext: cmds.HelpText{
Tagline: "Remove repo lockfiles.", Tagline: "Remove repo lockfiles.",
ShortDescription: ` ShortDescription: `
'ipfs repo fsck' is a plumbing command that will remove repo and level db 'ipfs repo fsck' is now a no-op.
lockfiles, as well as the api file. This command can only run when no ipfs
daemons are running.
`, `,
}, },
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
configRoot, err := cmdenv.GetConfigRoot(env) return cmds.EmitOnce(res, &MessageOutput{"`ipfs repo fsck` is deprecated and does nothing.\n"})
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"})
}, },
Type: MessageOutput{}, Type: MessageOutput{},
Encoders: cmds.EncoderMap{ Encoders: cmds.EncoderMap{
......
#!/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
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论