Skip to content

Commit a3c720e

Browse files
committed
Refactor.
License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
1 parent 7da4b1b commit a3c720e

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

core/commands/repo.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -300,31 +300,31 @@ This command can only run when the ipfs daemon is not running.
300300
res.SetError(err, cmdkit.ErrNormal)
301301
return
302302
}
303+
defer repo.Close()
303304

304305
// Get the old root and display it to the user so that they can
305306
// can do something to prevent from being garbage collected,
306307
// such as pin it
307308
dsk := core.FilesRootKey()
308309
val, err := repo.Datastore().Get(dsk)
309-
switch {
310-
case err == ds.ErrNotFound || val == nil:
310+
if err == ds.ErrNotFound || val == nil {
311+
if case err == ds.ErrNotFound || val == nil {
311312
cmds.EmitOnce(res, &MessageOutput{"Files API root not found.\n"})
312-
default:
313-
var cidStr string
314-
c, err := cid.Cast(val.([]byte))
315-
if err == nil {
316-
cidStr = c.String()
317-
} else {
318-
cidStr = b58.Encode(val.([]byte))
319-
}
320-
err = repo.Datastore().Delete(dsk)
321-
if err != nil {
322-
res.SetError(fmt.Errorf("unable to remove API root: %s. Root hash was %s", err.Error(), cidStr), cmdkit.ErrNormal)
323-
return
324-
}
325-
cmds.EmitOnce(res, &MessageOutput{fmt.Sprintf("Unlinked files API root. Root hash was %s.\n", cidStr)})
313+
return
314+
}
315+
var cidStr string
316+
c, err := cid.Cast(val.([]byte))
317+
if err == nil {
318+
cidStr = c.String()
319+
} else {
320+
cidStr = b58.Encode(val.([]byte))
321+
}
322+
err = repo.Datastore().Delete(dsk)
323+
if err != nil {
324+
res.SetError(fmt.Errorf("unable to remove API root: %s. Root hash was %s", err.Error(), cidStr), cmdkit.ErrNormal)
325+
return
326326
}
327-
repo.Close()
327+
cmds.EmitOnce(res, &MessageOutput{fmt.Sprintf("Unlinked files API root. Root hash was %s.\n", cidStr)})
328328
},
329329
Type: MessageOutput{},
330330
Encoders: cmds.EncoderMap{

0 commit comments

Comments
 (0)