Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
2a41e76b
Commit
2a41e76b
authored
7 years ago
by
Lewis Marshall
Committed by
Jeffrey Wilcke
7 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
swarm/api: Fix adding paths which exist as manifests (#14482)
Signed-off-by:
Lewis Marshall
<
lewis@lmars.net
>
parent
4a2c17b1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
2 deletions
+35
-2
manifest.go
swarm/api/manifest.go
+2
-2
manifest_test.go
swarm/api/manifest_test.go
+33
-0
No files found.
swarm/api/manifest.go
View file @
2a41e76b
...
...
@@ -237,12 +237,12 @@ func (self *manifestTrie) addEntry(entry *manifestTrieEntry, quitC chan bool) {
}
b
:=
byte
(
entry
.
Path
[
0
])
if
(
self
.
entries
[
b
]
==
nil
)
||
(
self
.
entries
[
b
]
.
Path
==
entry
.
Path
)
{
oldentry
:=
self
.
entries
[
b
]
if
(
oldentry
==
nil
)
||
(
oldentry
.
Path
==
entry
.
Path
&&
oldentry
.
ContentType
!=
ManifestType
)
{
self
.
entries
[
b
]
=
entry
return
}
oldentry
:=
self
.
entries
[
b
]
cpl
:=
0
for
(
len
(
entry
.
Path
)
>
cpl
)
&&
(
len
(
oldentry
.
Path
)
>
cpl
)
&&
(
entry
.
Path
[
cpl
]
==
oldentry
.
Path
[
cpl
])
{
cpl
++
...
...
This diff is collapsed.
Click to expand it.
swarm/api/manifest_test.go
View file @
2a41e76b
...
...
@@ -18,6 +18,8 @@ package api
import
(
// "encoding/json"
"bytes"
"encoding/json"
"fmt"
"io"
"strings"
...
...
@@ -78,3 +80,34 @@ func TestGetEntry(t *testing.T) {
func
TestDeleteEntry
(
t
*
testing
.
T
)
{
}
// TestAddFileWithManifestPath tests that adding an entry at a path which
// already exists as a manifest just adds the entry to the manifest rather
// than replacing the manifest with the entry
func
TestAddFileWithManifestPath
(
t
*
testing
.
T
)
{
// create a manifest containing "ab" and "ac"
manifest
,
_
:=
json
.
Marshal
(
&
Manifest
{
Entries
:
[]
ManifestEntry
{
{
Path
:
"ab"
,
Hash
:
"ab"
},
{
Path
:
"ac"
,
Hash
:
"ac"
},
},
})
reader
:=
&
storage
.
LazyTestSectionReader
{
SectionReader
:
io
.
NewSectionReader
(
bytes
.
NewReader
(
manifest
),
0
,
int64
(
len
(
manifest
))),
}
trie
,
err
:=
readManifest
(
reader
,
nil
,
nil
,
nil
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
checkEntry
(
t
,
"ab"
,
"ab"
,
trie
)
checkEntry
(
t
,
"ac"
,
"ac"
,
trie
)
// now add path "a" and check we can still get "ab" and "ac"
entry
:=
&
manifestTrieEntry
{}
entry
.
Path
=
"a"
entry
.
Hash
=
"a"
trie
.
addEntry
(
entry
,
nil
)
checkEntry
(
t
,
"ab"
,
"ab"
,
trie
)
checkEntry
(
t
,
"ac"
,
"ac"
,
trie
)
checkEntry
(
t
,
"a"
,
"a"
,
trie
)
}
This diff is collapsed.
Click to expand it.
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