1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-28 00:39:31 +08:00

Replace strings.Join(elms, "/") with path.Join(elms)

License: MIT
Signed-off-by: rht <rhtbot@gmail.com>
This commit is contained in:
rht
2015-11-17 15:36:48 +07:00
committed by Jeromy
parent 8abb12e760
commit ffd859232d
8 changed files with 31 additions and 24 deletions

View File

@ -13,8 +13,8 @@ import (
"fmt"
"io"
"reflect"
"strings"
"github.com/ipfs/go-ipfs/path"
logging "github.com/ipfs/go-ipfs/vendor/QmQg1J6vikuXF9oDvm4wpdeAUvvkVEKW1EYDw9HhTMnP2b/go-log"
)
@ -147,16 +147,16 @@ func (c *Command) Call(req Request) Response {
}
// Resolve gets the subcommands at the given path
func (c *Command) Resolve(path []string) ([]*Command, error) {
cmds := make([]*Command, len(path)+1)
func (c *Command) Resolve(pth []string) ([]*Command, error) {
cmds := make([]*Command, len(pth)+1)
cmds[0] = c
cmd := c
for i, name := range path {
for i, name := range pth {
cmd = cmd.Subcommand(name)
if cmd == nil {
pathS := strings.Join(path[0:i], "/")
pathS := path.Join(pth[0:i])
return nil, fmt.Errorf("Undefined command: '%s'", pathS)
}

View File

@ -13,6 +13,7 @@ import (
"strings"
cmds "github.com/ipfs/go-ipfs/commands"
path "github.com/ipfs/go-ipfs/path"
config "github.com/ipfs/go-ipfs/repo/config"
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
@ -85,8 +86,8 @@ func (c *client) Send(req cmds.Request) (cmds.Response, error) {
reader = fileReader
}
path := strings.Join(req.Path(), "/")
url := fmt.Sprintf(ApiUrlFormat, c.serverAddress, ApiPath, path, query)
pth := path.Join(req.Path())
url := fmt.Sprintf(ApiUrlFormat, c.serverAddress, ApiPath, pth, query)
httpReq, err := http.NewRequest("POST", url, reader)
if err != nil {

View File

@ -12,6 +12,7 @@ import (
cmds "github.com/ipfs/go-ipfs/commands"
notif "github.com/ipfs/go-ipfs/notifications"
peer "github.com/ipfs/go-ipfs/p2p/peer"
path "github.com/ipfs/go-ipfs/path"
ipdht "github.com/ipfs/go-ipfs/routing/dht"
u "github.com/ipfs/go-ipfs/util"
)
@ -605,7 +606,7 @@ func escapeDhtKey(s string) (key.Key, error) {
return key.B58KeyDecode(s), nil
case 3:
k := key.B58KeyDecode(parts[2])
return key.Key(strings.Join(append(parts[:2], string(k)), "/")), nil
return key.Key(path.Join(append(parts[:2], k.String()))), nil
default:
return "", errors.New("invalid key")
}

View File

@ -269,7 +269,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
if len(pathSplit) > 5 {
// also strip the trailing segment, because it's a backlink
backLinkParts := pathSplit[3 : len(pathSplit)-2]
backLink += strings.Join(backLinkParts, "/") + "/"
backLink += path.Join(backLinkParts) + "/"
}
}
@ -337,7 +337,7 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
var newPath string
if len(rsegs) > 1 {
newPath = strings.Join(rsegs[2:], "/")
newPath = path.Join(rsegs[2:])
}
var newkey key.Key
@ -462,7 +462,7 @@ func (i *gatewayHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {
i.addUserHeaders(w) // ok, _now_ write user's headers.
w.Header().Set("IPFS-Hash", key.String())
http.Redirect(w, r, ipfsPathPrefix+key.String()+"/"+strings.Join(components[:len(components)-1], "/"), http.StatusCreated)
http.Redirect(w, r, gopath.Join(ipfsPathPrefix+key.String(), path.Join(components[:len(components)-1])), http.StatusCreated)
}
func (i *gatewayHandler) addUserHeaders(w http.ResponseWriter) {

View File

@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"os"
"strings"
fuse "github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse"
fs "github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs"
@ -194,7 +193,7 @@ func (s *Root) Lookup(ctx context.Context, name string) (fs.Node, error) {
segments := resolved.Segments()
if segments[0] == "ipfs" {
p := strings.Join(resolved.Segments()[1:], "/")
p := path.Join(resolved.Segments()[1:])
return &Link{s.IpfsRoot + "/" + p}, nil
}

View File

@ -8,6 +8,7 @@ import (
"strings"
dag "github.com/ipfs/go-ipfs/merkledag"
path "github.com/ipfs/go-ipfs/path"
)
// Mv moves the file or directory at 'src' to 'dst'
@ -99,8 +100,8 @@ func PutNode(r *Root, path string, nd *dag.Node) error {
// Mkdir creates a directory at 'path' under the directory 'd', creating
// intermediary directories as needed if 'parents' is set to true
func Mkdir(r *Root, path string, parents bool) error {
parts := strings.Split(path, "/")
func Mkdir(r *Root, pth string, parents bool) error {
parts := strings.Split(pth, "/")
if parts[0] == "" {
parts = parts[1:]
}
@ -112,7 +113,7 @@ func Mkdir(r *Root, path string, parents bool) error {
if len(parts) == 0 {
// this will only happen on 'mkdir /'
return fmt.Errorf("cannot mkdir '%s'", path)
return fmt.Errorf("cannot mkdir '%s'", pth)
}
cur := r.GetValue().(*Directory)
@ -130,7 +131,7 @@ func Mkdir(r *Root, path string, parents bool) error {
next, ok := fsn.(*Directory)
if !ok {
return fmt.Errorf("%s was not a directory", strings.Join(parts[:i], "/"))
return fmt.Errorf("%s was not a directory", path.Join(parts[:i]))
}
cur = next
}
@ -156,9 +157,9 @@ func Lookup(r *Root, path string) (FSNode, error) {
// DirLookup will look up a file or directory at the given path
// under the directory 'd'
func DirLookup(d *Directory, path string) (FSNode, error) {
path = strings.Trim(path, "/")
parts := strings.Split(path, "/")
func DirLookup(d *Directory, pth string) (FSNode, error) {
pth = strings.Trim(pth, "/")
parts := strings.Split(pth, "/")
if len(parts) == 1 && parts[0] == "" {
return d, nil
}
@ -168,7 +169,7 @@ func DirLookup(d *Directory, path string) (FSNode, error) {
for i, p := range parts {
chdir, ok := cur.(*Directory)
if !ok {
return nil, fmt.Errorf("cannot access %s: Not a directory", strings.Join(parts[:i+1], "/"))
return nil, fmt.Errorf("cannot access %s: Not a directory", path.Join(parts[:i+1]))
}
child, err := chdir.Child(p)

View File

@ -102,3 +102,7 @@ func (p *Path) IsValid() error {
_, err := ParsePath(p.String())
return err
}
func Join(pths []string) string {
return strings.Join(pths, "/")
}

View File

@ -12,6 +12,7 @@ import (
chunk "github.com/ipfs/go-ipfs/importer/chunk"
dag "github.com/ipfs/go-ipfs/merkledag"
dagutil "github.com/ipfs/go-ipfs/merkledag/utils"
path "github.com/ipfs/go-ipfs/path"
uio "github.com/ipfs/go-ipfs/unixfs/io"
logging "github.com/ipfs/go-ipfs/vendor/QmQg1J6vikuXF9oDvm4wpdeAUvvkVEKW1EYDw9HhTMnP2b/go-log"
@ -96,12 +97,12 @@ func ImportTar(r io.Reader, ds dag.DAGService) (*dag.Node, error) {
// adds a '-' to the beginning of each path element so we can use 'data' as a
// special link in the structure without having to worry about
func escapePath(path string) string {
elems := strings.Split(strings.Trim(path, "/"), "/")
func escapePath(pth string) string {
elems := strings.Split(strings.Trim(pth, "/"), "/")
for i, e := range elems {
elems[i] = "-" + e
}
return strings.Join(elems, "/")
return path.Join(elems)
}
type tarReader struct {