Skip to content

Commit

Permalink
Refactor.
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
  • Loading branch information
kevina committed May 30, 2018
1 parent 7da4b1b commit 8a9a19b
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions core/commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,31 +300,30 @@ This command can only run when the ipfs daemon is not running.
res.SetError(err, cmdkit.ErrNormal)
return
}
defer repo.Close()

// Get the old root and display it to the user so that they can
// can do something to prevent from being garbage collected,
// such as pin it
dsk := core.FilesRootKey()
val, err := repo.Datastore().Get(dsk)
switch {
case err == ds.ErrNotFound || val == nil:
if case err == ds.ErrNotFound || val == nil {
cmds.EmitOnce(res, &MessageOutput{"Files API root not found.\n"})
default:
var cidStr string
c, err := cid.Cast(val.([]byte))
if err == nil {
cidStr = c.String()
} else {
cidStr = b58.Encode(val.([]byte))
}
err = repo.Datastore().Delete(dsk)
if err != nil {
res.SetError(fmt.Errorf("unable to remove API root: %s. Root hash was %s", err.Error(), cidStr), cmdkit.ErrNormal)
return
}
cmds.EmitOnce(res, &MessageOutput{fmt.Sprintf("Unlinked files API root. Root hash was %s.\n", cidStr)})
return
}
var cidStr string
c, err := cid.Cast(val.([]byte))
if err == nil {
cidStr = c.String()
} else {
cidStr = b58.Encode(val.([]byte))
}
err = repo.Datastore().Delete(dsk)
if err != nil {
res.SetError(fmt.Errorf("unable to remove API root: %s. Root hash was %s", err.Error(), cidStr), cmdkit.ErrNormal)
return
}
repo.Close()
cmds.EmitOnce(res, &MessageOutput{fmt.Sprintf("Unlinked files API root. Root hash was %s.\n", cidStr)})
},
Type: MessageOutput{},
Encoders: cmds.EncoderMap{
Expand Down

0 comments on commit 8a9a19b

Please sign in to comment.