aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/api
diff options
context:
space:
mode:
authorLewis Marshall <lewis@lmars.net>2017-05-22 14:57:03 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2017-05-22 14:57:03 +0800
commit2a41e76b39f8279400e42f3e0dc45f55457e2cff (patch)
tree2d0e34836a3280357d1c375bd761159417a6efa7 /swarm/api
parent4a2c17b1ab8316ab3b4fa2b769d1dccad3cb97d5 (diff)
downloaddexon-2a41e76b39f8279400e42f3e0dc45f55457e2cff.tar.gz
dexon-2a41e76b39f8279400e42f3e0dc45f55457e2cff.tar.zst
dexon-2a41e76b39f8279400e42f3e0dc45f55457e2cff.zip
swarm/api: Fix adding paths which exist as manifests (#14482)
Signed-off-by: Lewis Marshall <lewis@lmars.net>
Diffstat (limited to 'swarm/api')
-rw-r--r--swarm/api/manifest.go4
-rw-r--r--swarm/api/manifest_test.go33
2 files changed, 35 insertions, 2 deletions
diff --git a/swarm/api/manifest.go b/swarm/api/manifest.go
index dbaaf4bff..e251620a7 100644
--- a/swarm/api/manifest.go
+++ b/swarm/api/manifest.go
@@ -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++
diff --git a/swarm/api/manifest_test.go b/swarm/api/manifest_test.go
index 20b8117c6..0208848a3 100644
--- a/swarm/api/manifest_test.go
+++ b/swarm/api/manifest_test.go
@@ -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)
+}