fixed manifestTrie.getEntry

This commit is contained in:
zsfelfoldi 2015-05-30 16:27:09 +02:00
parent e6806dce6a
commit 9b361532e0
2 changed files with 15 additions and 1 deletions

View file

@ -309,14 +309,17 @@ func (self *Api) getPath(uri string) (reader SectionReader, mimeType string, sta
var key Key var key Key
key, err = self.Resolve(hostPort) key, err = self.Resolve(hostPort)
if err != nil { if err != nil {
dpaLogger.Debugf("Swarm: rResolve error: %v", err)
return return
} }
trie, err := loadManifestTrie(self.dpa, key) trie, err := loadManifestTrie(self.dpa, key)
if err != nil { if err != nil {
dpaLogger.Debugf("Swarm: loadManifestTrie error: %v", err)
return return
} }
dpaLogger.Debugf("Swarm: getEntry(%s)", path)
entry, _ := trie.getEntry(path) entry, _ := trie.getEntry(path)
if entry != nil { if entry != nil {
key = common.Hex2Bytes(entry.Hash) key = common.Hex2Bytes(entry.Hash)
@ -324,6 +327,8 @@ func (self *Api) getPath(uri string) (reader SectionReader, mimeType string, sta
mimeType = entry.ContentType mimeType = entry.ContentType
dpaLogger.Debugf("Swarm: content lookup key: '%064x' (%v)", key, mimeType) dpaLogger.Debugf("Swarm: content lookup key: '%064x' (%v)", key, mimeType)
reader = self.dpa.Retrieve(key) reader = self.dpa.Retrieve(key)
} else {
dpaLogger.Debugf("Swarm: getEntry(%s): not found", path)
} }
return return
} }

View file

@ -205,14 +205,22 @@ func (self *manifestTrie) loadSubTrie(entry *manifestTrieEntry) (err error) {
} }
func (self *manifestTrie) findPrefixOf(path string) (entry *manifestTrieEntry, pos int) { func (self *manifestTrie) findPrefixOf(path string) (entry *manifestTrieEntry, pos int) {
dpaLogger.Debugf("findPrefixOf(%s)", path)
if len(path) == 0 { if len(path) == 0 {
return self.entries[256], 0 return self.entries[256], 0
} }
b := byte(path[0]) b := byte(path[0])
entry = self.entries[b] entry = self.entries[b]
if entry == nil {
return nil, 0
}
epl := len(entry.Path) epl := len(entry.Path)
dpaLogger.Debugf("path = %v entry.Path = %v epl = %v", path, entry.Path, epl)
if (len(path) >= epl) && (path[:epl] == entry.Path) { if (len(path) >= epl) && (path[:epl] == entry.Path) {
dpaLogger.Debugf("entry.ContentType = %v", entry.ContentType)
if entry.ContentType == manifestType { if entry.ContentType == manifestType {
if self.loadSubTrie(entry) != nil { if self.loadSubTrie(entry) != nil {
return nil, 0 return nil, 0
@ -236,7 +244,7 @@ func (self *manifestTrie) getEntryNLS(path string) (entry *manifestTrieEntry, po
for (pos < len(path)) && (path[pos] == '/') { for (pos < len(path)) && (path[pos] == '/') {
pos++ pos++
} }
if (pos > 0) && (path[pos-1] != '/') { if (pos < len(path)) && (pos > 0) && (path[pos-1] != '/') {
return nil, 0 return nil, 0
} }
} }
@ -247,6 +255,7 @@ func (self *manifestTrie) getEntry(path string) (entry *manifestTrieEntry, pos i
var slash string var slash string
for { for {
entry, pos = self.getEntryNLS(slash + path) entry, pos = self.getEntryNLS(slash + path)
dpaLogger.Debugf("getEntryNLS(%s) pos=%v", slash+path, pos)
if pos < len(slash) { if pos < len(slash) {
dpaLogger.Debugf("Path '%s' on manifest not found.", path) dpaLogger.Debugf("Path '%s' on manifest not found.", path)
return nil, 0 return nil, 0