From ff2081f5fd062c7101b9d32ff12b0e7f16e66b7f Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Thu, 28 May 2015 14:59:23 +0200 Subject: [PATCH] fixed manifest relative path --- bzz/api.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/bzz/api.go b/bzz/api.go index 5d55073a83..8322252519 100644 --- a/bzz/api.go +++ b/bzz/api.go @@ -113,9 +113,20 @@ func (self *Api) Download(bzzpath, localpath string) (string, error) { func (self *Api) Upload(localpath string) (string, error) { var files []string localpath = common.ExpandHomePath(localpath) + start := len(localpath) + if (start > 0) && (localpath[start-1] != os.PathSeparator) { + start++ + } dpaLogger.Debugf("uploading '%s'", localpath) err := filepath.Walk(localpath, func(path string, info os.FileInfo, err error) error { - if err == nil { + if (err == nil) && !info.IsDir() { + //fmt.Printf("lp %s path %s\n", localpath, path) + if len(path) <= start { + return fmt.Errorf("Path is too short") + } + if path[:len(localpath)] != localpath { + return fmt.Errorf("Path prefix does not match localpath") + } files = append(files, path) } return err @@ -147,9 +158,6 @@ func (self *Api) Upload(localpath string) (string, error) { var buffer bytes.Buffer buffer.WriteString(`{"entries":[`) sc := "," - var pathPrefix *regexp.Regexp - var relativePath string - pathPrefix, err = regexp.Compile("^" + localpath + fmt.Sprintf("%s", os.PathSeparator)) if err != nil { return "", err } @@ -161,8 +169,7 @@ func (self *Api) Upload(localpath string) (string, error) { if i == cnt-1 { sc = "]}" } - relativePath = pathPrefix.ReplaceAllString(path, "") - buffer.WriteString(fmt.Sprintf(`{"hash":"%064x","path":"%s","contentType":"text/plain"}%s`, hashes[i], relativePath, sc)) + buffer.WriteString(fmt.Sprintf(`{"hash":"%064x","path":"%s","contentType":"text/plain"}%s`, hashes[i], path[start:], sc)) } manifest := buffer.Bytes()