mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
fix manifest path matching slashes issue
This commit is contained in:
parent
0501ff41d0
commit
38d1bdf688
2 changed files with 22 additions and 5 deletions
|
|
@ -93,6 +93,9 @@ func (self *Api) Stop() {
|
||||||
func (self *Api) Get(bzzpath string) (content []byte, mimeType string, status int, size int, err error) {
|
func (self *Api) Get(bzzpath string) (content []byte, mimeType string, status int, size int, err error) {
|
||||||
var reader SectionReader
|
var reader SectionReader
|
||||||
reader, mimeType, status, err = self.getPath("/" + bzzpath)
|
reader, mimeType, status, err = self.getPath("/" + bzzpath)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
content = make([]byte, reader.Size())
|
content = make([]byte, reader.Size())
|
||||||
size, err = reader.Read(content)
|
size, err = reader.Read(content)
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,18 @@
|
||||||
package bzz
|
package bzz
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "fmt"
|
// "fmt"
|
||||||
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
manifestType = "application/bzz-manifest+json"
|
manifestType = "application/bzz-manifest+json"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
leadingSlashes = regexp.MustCompile("^/+")
|
||||||
|
)
|
||||||
|
|
||||||
type manifest struct {
|
type manifest struct {
|
||||||
Entries []*manifestEntry `json:"entries"`
|
Entries []*manifestEntry `json:"entries"`
|
||||||
}
|
}
|
||||||
|
|
@ -21,12 +26,21 @@ type manifestEntry struct {
|
||||||
|
|
||||||
func (self *manifest) getEntry(path string) (entry *manifestEntry, pos int) {
|
func (self *manifest) getEntry(path string) (entry *manifestEntry, pos int) {
|
||||||
for _, entry = range self.Entries {
|
for _, entry = range self.Entries {
|
||||||
pos = len(entry.Path)
|
entryPath := leadingSlashes.ReplaceAllString(entry.Path, "")
|
||||||
if len(path) >= pos && path[:pos] == entry.Path {
|
pos = len(entryPath)
|
||||||
|
if len(path) >= pos && path[:pos] == entryPath {
|
||||||
|
var n int
|
||||||
|
if len(path) > pos {
|
||||||
|
chopped := leadingSlashes.ReplaceAllString(path[pos:], "")
|
||||||
|
n = len(path) - pos - len(chopped)
|
||||||
|
}
|
||||||
|
if n > 0 || pos == 0 || path[pos-1] == '/' {
|
||||||
|
pos += n
|
||||||
dpaLogger.Debugf("Swarm: '%s' matches '%s'.", path, entry.Path)
|
dpaLogger.Debugf("Swarm: '%s' matches '%s'.", path, entry.Path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
entry = nil
|
entry = nil
|
||||||
dpaLogger.Debugf("Path '%s' on manifest not found.", path)
|
dpaLogger.Debugf("Path '%s' on manifest not found.", path)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue