Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
e4e35047
Unverified
Commit
e4e35047
authored
Sep 14, 2018
by
Steven Allen
Committed by
GitHub
Sep 14, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5465 from rob-deutsch/fix/5450
fix behaviour of key rename to same name
parents
cbc6e69e
b06a0b0e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
1 deletion
+63
-1
core/coreapi/key.go
core/coreapi/key.go
+7
-1
core/coreapi/key_test.go
core/coreapi/key_test.go
+56
-0
No files found.
core/coreapi/key.go
View file @
e4e35047
...
...
@@ -8,10 +8,10 @@ import (
coreiface
"github.com/ipfs/go-ipfs/core/coreapi/interface"
caopts
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
ipfspath
"gx/ipfs/QmX7uSbkNz76yNwBhuwYwRbhihLnJqM73VTCjS3UMJud9A/go-path"
crypto
"gx/ipfs/QmPvyPwuCgJ7pDmrKDxRtsScJgBaM5h4EpRL2qQJsmXf4n/go-libp2p-crypto"
peer
"gx/ipfs/QmQsErDt8Qgw1XrsXf2BpEzDgGWtB1YLsTAARBup5b6B9W/go-libp2p-peer"
ipfspath
"gx/ipfs/QmX7uSbkNz76yNwBhuwYwRbhihLnJqM73VTCjS3UMJud9A/go-path"
)
type
KeyAPI
CoreAPI
...
...
@@ -159,6 +159,12 @@ func (api *KeyAPI) Rename(ctx context.Context, oldName string, newName string, o
return
nil
,
false
,
err
}
// This is important, because future code will delete key `oldName`
// even if it is the same as newName.
if
newName
==
oldName
{
return
&
key
{
oldName
,
pid
},
false
,
nil
}
overwrite
:=
false
if
options
.
Force
{
exist
,
err
:=
ks
.
Has
(
newName
)
...
...
core/coreapi/key_test.go
View file @
e4e35047
...
...
@@ -366,6 +366,62 @@ func TestRenameOverwrite(t *testing.T) {
}
}
func
TestRenameSameNameNoForce
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
_
,
api
,
err
:=
makeAPI
(
ctx
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
_
,
err
=
api
.
Key
()
.
Generate
(
ctx
,
"foo"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
k
,
overwrote
,
err
:=
api
.
Key
()
.
Rename
(
ctx
,
"foo"
,
"foo"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
if
overwrote
{
t
.
Error
(
"overwrote should be false"
)
}
if
k
.
Name
()
!=
"foo"
{
t
.
Errorf
(
"returned key should be called 'foo', got '%s'"
,
k
.
Name
())
}
}
func
TestRenameSameName
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
_
,
api
,
err
:=
makeAPI
(
ctx
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
_
,
err
=
api
.
Key
()
.
Generate
(
ctx
,
"foo"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
k
,
overwrote
,
err
:=
api
.
Key
()
.
Rename
(
ctx
,
"foo"
,
"foo"
,
opt
.
Key
.
Force
(
true
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
if
overwrote
{
t
.
Error
(
"overwrote should be false"
)
}
if
k
.
Name
()
!=
"foo"
{
t
.
Errorf
(
"returned key should be called 'foo', got '%s'"
,
k
.
Name
())
}
}
func
TestRemove
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
_
,
api
,
err
:=
makeAPI
(
ctx
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment