Skip to content

Commit

Permalink
Replace strings.Join(elms, "/") with path.Join(elms)
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: rht <[email protected]>
  • Loading branch information
rht committed Nov 24, 2015
1 parent d46c0d4 commit 8ffc9ea
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 24 deletions.
10 changes: 5 additions & 5 deletions commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -143,16 +143,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)
}

Expand Down
5 changes: 3 additions & 2 deletions commands/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -85,8 +86,8 @@ func (c *client) Send(req cmds.Request) (cmds.Response, error) {
reader = strings.NewReader("")
}

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 {
Expand Down
3 changes: 2 additions & 1 deletion core/commands/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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")
}
Expand Down
6 changes: 3 additions & 3 deletions core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,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) + "/"
}
}

Expand Down Expand Up @@ -304,7 +304,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
Expand Down Expand Up @@ -429,7 +429,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) {
Expand Down
3 changes: 1 addition & 2 deletions fuse/ipns/ipns_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
17 changes: 9 additions & 8 deletions mfs/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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:]
}
Expand All @@ -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)
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions path/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@ func (p *Path) IsValid() error {
_, err := ParsePath(p.String())
return err
}

func Join(pths []string) string {
return strings.Join(pths, "/")
}
7 changes: 4 additions & 3 deletions tar/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8ffc9ea

Please sign in to comment.