@cryptotaxi247 / kubo / commits / ffd859232

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

License: MIT Signed-off-by: rht <rhtbot@gmail.com>

rht committed Nov 17, 2015 at 15:36 UTC ffd859232d82561e49662a95a67bb297933e6d07
8 files changed +31 -24
commands/command.go
+5 -5
@@ -13,8 +13,8 @@ import (
13 "fmt"
14 "io"
15 "reflect"
16 - "strings"
16
17 + "github.com/ipfs/go-ipfs/path"
18 logging "github.com/ipfs/go-ipfs/vendor/QmQg1J6vikuXF9oDvm4wpdeAUvvkVEKW1EYDw9HhTMnP2b/go-log"
19 )
20
@@ -147,16 +147,16 @@ func (c *Command) Call(req Request) Response {
147 }
148
149 // Resolve gets the subcommands at the given path
150 -func (c *Command) Resolve(path []string) ([]*Command, error) {
151 - cmds := make([]*Command, len(path)+1)
150 +func (c *Command) Resolve(pth []string) ([]*Command, error) {
151 + cmds := make([]*Command, len(pth)+1)
152 cmds[0] = c
153
154 cmd := c
155 - for i, name := range path {
155 + for i, name := range pth {
156 cmd = cmd.Subcommand(name)
157
158 if cmd == nil {
159 - pathS := strings.Join(path[0:i], "/")
159 + pathS := path.Join(pth[0:i])
160 return nil, fmt.Errorf("Undefined command: '%s'", pathS)
161 }
162
commands/http/client.go
+3 -2
@@ -13,6 +13,7 @@ import (
13 "strings"
14
15 cmds "github.com/ipfs/go-ipfs/commands"
16 + path "github.com/ipfs/go-ipfs/path"
17 config "github.com/ipfs/go-ipfs/repo/config"
18
19 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) {
86 reader = fileReader
87 }
88
88 - path := strings.Join(req.Path(), "/")
89 - url := fmt.Sprintf(ApiUrlFormat, c.serverAddress, ApiPath, path, query)
89 + pth := path.Join(req.Path())
90 + url := fmt.Sprintf(ApiUrlFormat, c.serverAddress, ApiPath, pth, query)
91
92 httpReq, err := http.NewRequest("POST", url, reader)
93 if err != nil {
core/commands/dht.go
+2 -1
@@ -12,6 +12,7 @@ import (
12 cmds "github.com/ipfs/go-ipfs/commands"
13 notif "github.com/ipfs/go-ipfs/notifications"
14 peer "github.com/ipfs/go-ipfs/p2p/peer"
15 + path "github.com/ipfs/go-ipfs/path"
16 ipdht "github.com/ipfs/go-ipfs/routing/dht"
17 u "github.com/ipfs/go-ipfs/util"
18 )
@@ -605,7 +606,7 @@ func escapeDhtKey(s string) (key.Key, error) {
606 return key.B58KeyDecode(s), nil
607 case 3:
608 k := key.B58KeyDecode(parts[2])
608 - return key.Key(strings.Join(append(parts[:2], string(k)), "/")), nil
609 + return key.Key(path.Join(append(parts[:2], k.String()))), nil
610 default:
611 return "", errors.New("invalid key")
612 }
core/corehttp/gateway_handler.go
+3 -3
@@ -269,7 +269,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
269 if len(pathSplit) > 5 {
270 // also strip the trailing segment, because it's a backlink
271 backLinkParts := pathSplit[3 : len(pathSplit)-2]
272 - backLink += strings.Join(backLinkParts, "/") + "/"
272 + backLink += path.Join(backLinkParts) + "/"
273 }
274 }
275
@@ -337,7 +337,7 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
337
338 var newPath string
339 if len(rsegs) > 1 {
340 - newPath = strings.Join(rsegs[2:], "/")
340 + newPath = path.Join(rsegs[2:])
341 }
342
343 var newkey key.Key
@@ -462,7 +462,7 @@ func (i *gatewayHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {
462
463 i.addUserHeaders(w) // ok, _now_ write user's headers.
464 w.Header().Set("IPFS-Hash", key.String())
465 - http.Redirect(w, r, ipfsPathPrefix+key.String()+"/"+strings.Join(components[:len(components)-1], "/"), http.StatusCreated)
465 + http.Redirect(w, r, gopath.Join(ipfsPathPrefix+key.String(), path.Join(components[:len(components)-1])), http.StatusCreated)
466 }
467
468 func (i *gatewayHandler) addUserHeaders(w http.ResponseWriter) {
fuse/ipns/ipns_unix.go
+1 -2
@@ -8,7 +8,6 @@ import (
8 "errors"
9 "fmt"
10 "os"
11 - "strings"
11
12 fuse "github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse"
13 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) {
193
194 segments := resolved.Segments()
195 if segments[0] == "ipfs" {
197 - p := strings.Join(resolved.Segments()[1:], "/")
196 + p := path.Join(resolved.Segments()[1:])
197 return &Link{s.IpfsRoot + "/" + p}, nil
198 }
199
mfs/ops.go
+9 -8
@@ -8,6 +8,7 @@ import (
8 "strings"
9
10 dag "github.com/ipfs/go-ipfs/merkledag"
11 + path "github.com/ipfs/go-ipfs/path"
12 )
13
14 // Mv moves the file or directory at 'src' to 'dst'
@@ -99,8 +100,8 @@ func PutNode(r *Root, path string, nd *dag.Node) error {
100
101 // Mkdir creates a directory at 'path' under the directory 'd', creating
102 // intermediary directories as needed if 'parents' is set to true
102 -func Mkdir(r *Root, path string, parents bool) error {
103 - parts := strings.Split(path, "/")
103 +func Mkdir(r *Root, pth string, parents bool) error {
104 + parts := strings.Split(pth, "/")
105 if parts[0] == "" {
106 parts = parts[1:]
107 }
@@ -112,7 +113,7 @@ func Mkdir(r *Root, path string, parents bool) error {
113
114 if len(parts) == 0 {
115 // this will only happen on 'mkdir /'
115 - return fmt.Errorf("cannot mkdir '%s'", path)
116 + return fmt.Errorf("cannot mkdir '%s'", pth)
117 }
118
119 cur := r.GetValue().(*Directory)
@@ -130,7 +131,7 @@ func Mkdir(r *Root, path string, parents bool) error {
131
132 next, ok := fsn.(*Directory)
133 if !ok {
133 - return fmt.Errorf("%s was not a directory", strings.Join(parts[:i], "/"))
134 + return fmt.Errorf("%s was not a directory", path.Join(parts[:i]))
135 }
136 cur = next
137 }
@@ -156,9 +157,9 @@ func Lookup(r *Root, path string) (FSNode, error) {
157
158 // DirLookup will look up a file or directory at the given path
159 // under the directory 'd'
159 -func DirLookup(d *Directory, path string) (FSNode, error) {
160 - path = strings.Trim(path, "/")
161 - parts := strings.Split(path, "/")
160 +func DirLookup(d *Directory, pth string) (FSNode, error) {
161 + pth = strings.Trim(pth, "/")
162 + parts := strings.Split(pth, "/")
163 if len(parts) == 1 && parts[0] == "" {
164 return d, nil
165 }
@@ -168,7 +169,7 @@ func DirLookup(d *Directory, path string) (FSNode, error) {
169 for i, p := range parts {
170 chdir, ok := cur.(*Directory)
171 if !ok {
171 - return nil, fmt.Errorf("cannot access %s: Not a directory", strings.Join(parts[:i+1], "/"))
172 + return nil, fmt.Errorf("cannot access %s: Not a directory", path.Join(parts[:i+1]))
173 }
174
175 child, err := chdir.Child(p)
path/path.go
+4
@@ -102,3 +102,7 @@ func (p *Path) IsValid() error {
102 _, err := ParsePath(p.String())
103 return err
104 }
105 +
106 +func Join(pths []string) string {
107 + return strings.Join(pths, "/")
108 +}
tar/format.go
+4 -3
@@ -12,6 +12,7 @@ import (
12 chunk "github.com/ipfs/go-ipfs/importer/chunk"
13 dag "github.com/ipfs/go-ipfs/merkledag"
14 dagutil "github.com/ipfs/go-ipfs/merkledag/utils"
15 + path "github.com/ipfs/go-ipfs/path"
16 uio "github.com/ipfs/go-ipfs/unixfs/io"
17 logging "github.com/ipfs/go-ipfs/vendor/QmQg1J6vikuXF9oDvm4wpdeAUvvkVEKW1EYDw9HhTMnP2b/go-log"
18
@@ -96,12 +97,12 @@ func ImportTar(r io.Reader, ds dag.DAGService) (*dag.Node, error) {
97
98 // adds a '-' to the beginning of each path element so we can use 'data' as a
99 // special link in the structure without having to worry about
99 -func escapePath(path string) string {
100 - elems := strings.Split(strings.Trim(path, "/"), "/")
100 +func escapePath(pth string) string {
101 + elems := strings.Split(strings.Trim(pth, "/"), "/")
102 for i, e := range elems {
103 elems[i] = "-" + e
104 }
104 - return strings.Join(elems, "/")
105 + return path.Join(elems)
106 }
107
108 type tarReader struct {