@cryptotaxi247 / kubo / commits / 288a83ce7

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

Steven Allen committed Jun 29, 2019 at 11:15 UTC 288a83ce7dcbf4a2498e06e4a95245bbb5e30f45
2 files changed +2 -227
core/commands/repo.go
+2 -37
@@ -6,7 +6,6 @@ import (
6 "fmt"
7 "io"
8 "os"
9 - "path/filepath"
9 "runtime"
10 "strings"
11 "sync"
@@ -20,7 +19,6 @@ import (
19 cid "github.com/ipfs/go-cid"
20 bstore "github.com/ipfs/go-ipfs-blockstore"
21 cmds "github.com/ipfs/go-ipfs-cmds"
23 - config "github.com/ipfs/go-ipfs-config"
22 )
23
24 type RepoVersion struct {
@@ -216,44 +214,11 @@ var repoFsckCmd = &cmds.Command{
214 Helptext: cmds.HelpText{
215 Tagline: "Remove repo lockfiles.",
216 ShortDescription: `
219 -'ipfs repo fsck' is a plumbing command that will remove repo and level db
220 -lockfiles, as well as the api file. This command can only run when no ipfs
221 -daemons are running.
217 +'ipfs repo fsck' is now a no-op.
218 `,
219 },
220 Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
225 - configRoot, err := cmdenv.GetConfigRoot(env)
226 - if err != nil {
227 - return err
228 - }
229 -
230 - dsPath, err := config.DataStorePath(configRoot)
231 - if err != nil {
232 - return err
233 - }
234 -
235 - dsLockFile := filepath.Join(dsPath, "LOCK") // TODO: get this lockfile programmatically
236 - repoLockFile := filepath.Join(configRoot, fsrepo.LockFile)
237 - apiFile := filepath.Join(configRoot, "api") // TODO: get this programmatically
238 -
239 - log.Infof("Removing repo lockfile: %s", repoLockFile)
240 - log.Infof("Removing datastore lockfile: %s", dsLockFile)
241 - log.Infof("Removing api file: %s", apiFile)
242 -
243 - err = os.Remove(repoLockFile)
244 - if err != nil && !os.IsNotExist(err) {
245 - return err
246 - }
247 - err = os.Remove(dsLockFile)
248 - if err != nil && !os.IsNotExist(err) {
249 - return err
250 - }
251 - err = os.Remove(apiFile)
252 - if err != nil && !os.IsNotExist(err) {
253 - return err
254 - }
255 -
256 - return cmds.EmitOnce(res, &MessageOutput{"Lockfiles have been removed.\n"})
221 + return cmds.EmitOnce(res, &MessageOutput{"`ipfs repo fsck` is deprecated and does nothing.\n"})
222 },
223 Type: MessageOutput{},
224 Encoders: cmds.EncoderMap{
test/sharness/t0083-repo-fsck.sh deleted
-190
@@ -1,190 +0,0 @@
1 -#!/usr/bin/env bash
2 -#
3 -# Copyright (c) 2016 Mike Pfister
4 -# MIT Licensed; see the LICENSE file in this repository.
5 -#
6 -
7 -test_description="Test ipfs repo fsck operations"
8 -
9 -. lib/test-lib.sh
10 -
11 -test_init_ipfs
12 -
13 -#############################
14 -# Test without daemon running
15 -#############################
16 -# NOTE: if api file isn't present we can assume the daemon isn't running
17 -
18 -# Try with all lock files present: repo.lock, api, and datastore/LOCK with
19 -# repo.lock and datastore/LOCK being empty
20 -test_expect_success "'ipfs repo fsck' succeeds with no daemon running empty
21 -repo.lock" '
22 - mkdir -p $IPFS_PATH &&
23 - mkdir -p $IPFS_PATH/datastore &&
24 - touch $IPFS_PATH/datastore/LOCK &&
25 - touch $IPFS_PATH/repo.lock &&
26 - printf "/ip4/127.0.0.1/tcp/5001" > "$IPFS_PATH/api" &&
27 - ipfs repo fsck > fsck_out_actual1
28 -'
29 -test_expect_success "'ipfs repo fsck' output looks good with no daemon" '
30 - grep "Lockfiles have been removed." fsck_out_actual1
31 -'
32 -
33 -# Make sure the files are actually removed
34 -test_expect_success "'ipfs repo fsck' confirm file deletion" '
35 - test ! -e "$IPFS_PATH/repo.lock" &&
36 - test ! -e "$IPFS_PATH/datastore/LOCK" &&
37 - test ! -e "$IPFS_PATH/api"
38 -'
39 -
40 -# Try with all lock files present: repo.lock, api, and datastore/LOCK with
41 -# repo.lock is non-zero TODO: this test is broken until we find consensus on the
42 -# non-zero repo.lock issue
43 -test_expect_success "'ipfs repo fsck' succeeds with no daemon running non-zero
44 -repo.lock" '
45 - mkdir -p "$IPFS_PATH" &&
46 - printf ":D" > "$IPFS_PATH/repo.lock" &&
47 - touch "$IPFS_PATH/datastore/LOCK" &&
48 - ipfs repo fsck > fsck_out_actual1b
49 -'
50 -test_expect_success "'ipfs repo fsck' output looks good with no daemon" '
51 - grep "Lockfiles have been removed." fsck_out_actual1b
52 -'
53 -
54 -# Make sure the files are actually removed
55 -test_expect_success "'ipfs repo fsck' confirm file deletion" '
56 - test ! -e "$IPFS_PATH/repo.lock" &&
57 - test ! -e "$IPFS_PATH/datastore/LOCK" &&
58 - test ! -e "$IPFS_PATH/api"
59 -'
60 -
61 -########################
62 -# Test for partial locks
63 -########################
64 -
65 -# Try with locks api and datastore/LOCK
66 -test_expect_success "'ipfs repo fsck' succeeds partial lock" '
67 - printf "/ip4/127.0.0.1/tcp/5001" > "$IPFS_PATH/api" &&
68 - touch $IPFS_PATH/datastore/LOCK &&
69 - ipfs repo fsck > fsck_out_actual2
70 -'
71 -
72 -test_expect_success "'ipfs repo fsck' output looks good with no daemon" '
73 - grep "Lockfiles have been removed." fsck_out_actual2
74 -'
75 -
76 -# Make sure the files are actually removed
77 -test_expect_success "'ipfs repo fsck' confirm file deletion" '
78 - test ! -e "$IPFS_PATH/repo.lock" &&
79 - test ! -e "$IPFS_PATH/datastore/LOCK" &&
80 - test ! -e "$IPFS_PATH/api"
81 -'
82 -
83 -# Try with locks api and repo.lock
84 -test_expect_success "'ipfs repo fsck' succeeds partial lock" '
85 - printf "/ip4/127.0.0.1/tcp/5001" > "$IPFS_PATH/api" &&
86 - touch $IPFS_PATH/repo.lock &&
87 - ipfs repo fsck > fsck_out_actual3
88 -'
89 -
90 -test_expect_success "'ipfs repo fsck' output looks good with no daemon" '
91 - grep "Lockfiles have been removed." fsck_out_actual3
92 -'
93 -
94 -# Make sure the files are actually removed
95 -test_expect_success "'ipfs repo fsck' confirm file deletion" '
96 - test ! -e "$IPFS_PATH/repo.lock" &&
97 - test ! -e "$IPFS_PATH/datastore/LOCK" &&
98 - test ! -e "$IPFS_PATH/api"
99 -'
100 -
101 -# Try with locks repo.lock and datastore
102 -test_expect_success "'ipfs repo fsck' succeeds partial lock" '
103 - touch $IPFS_PATH/repo.lock &&
104 - touch $IPFS_PATH/datastore/LOCK &&
105 - ipfs repo fsck > fsck_out_actual4
106 -'
107 -
108 -test_expect_success "'ipfs repo fsck' output looks good with no daemon" '
109 - grep "Lockfiles have been removed." fsck_out_actual4
110 -'
111 -
112 -# Make sure the files are actually removed
113 -test_expect_success "'ipfs repo fsck' confirm file deletion" '
114 - test ! -e "$IPFS_PATH/repo.lock" &&
115 - test ! -e "$IPFS_PATH/datastore/LOCK" &&
116 - test ! -e "$IPFS_PATH/api"
117 -'
118 -
119 -#######################
120 -# Test for single locks
121 -#######################
122 -
123 -# Try with single locks repo.lock
124 -test_expect_success "'ipfs repo fsck' succeeds partial lock" '
125 - touch $IPFS_PATH/repo.lock &&
126 - ipfs repo fsck > fsck_out_actual5
127 -'
128 -test_expect_success "'ipfs repo fsck' output looks good with no daemon" '
129 - grep "Lockfiles have been removed." fsck_out_actual5
130 -'
131 -
132 -# Make sure the files are actually removed
133 -test_expect_success "'ipfs repo fsck' confirm file deletion" '
134 - test ! -e "$IPFS_PATH/repo.lock" &&
135 - test ! -e "$IPFS_PATH/datastore/LOCK" &&
136 - test ! -e "$IPFS_PATH/api"
137 -'
138 -
139 -# Try with single locks datastore/LOCK
140 -test_expect_success "'ipfs repo fsck' succeeds partial lock" '
141 - touch $IPFS_PATH/datastore/LOCK &&
142 - ipfs repo fsck > fsck_out_actual6
143 -'
144 -test_expect_success "'ipfs repo fsck' output looks good with no daemon" '
145 - grep "Lockfiles have been removed." fsck_out_actual6
146 -'
147 -
148 -# Make sure the files are actually removed
149 -test_expect_success "'ipfs repo fsck' confirm file deletion" '
150 - test ! -e "$IPFS_PATH/repo.lock" &&
151 - test ! -e "$IPFS_PATH/datastore/LOCK" &&
152 - test ! -e "$IPFS_PATH/api"
153 -'
154 -
155 -# Try with single lock api
156 -test_expect_success "'ipfs repo fsck' succeeds partial lock" '
157 - printf "/ip4/127.0.0.1/tcp/5001" > "$IPFS_PATH/api" &&
158 - ipfs repo fsck > fsck_out_actual7
159 -'
160 -
161 -test_expect_success "'ipfs repo fsck' output looks good with no daemon" '
162 - grep "Lockfiles have been removed." fsck_out_actual7
163 -'
164 -
165 -# Make sure the files are actually removed
166 -test_expect_success "'ipfs repo fsck' confirm file deletion" '
167 - test ! -e "$IPFS_PATH/repo.lock" &&
168 - test ! -e "$IPFS_PATH/datastore/LOCK" &&
169 - test ! -e "$IPFS_PATH/api"
170 -'
171 -
172 -##########################
173 -# Test with daemon running
174 -##########################
175 -
176 -test_launch_ipfs_daemon
177 -
178 -# Daemon is running -> command doesn't run
179 -test_expect_success "'ipfs repo fsck' fails with daemon running" '
180 - ! (ipfs repo fsck 2>fsck_out_actual8 )
181 -
182 -'
183 -
184 -test_expect_success "'ipfs repo fsck' output looks good with daemon" '
185 - grep "Error: ipfs daemon is running" fsck_out_actual8
186 -'
187 -
188 -test_kill_ipfs_daemon
189 -
190 -test_done