Fix path parsing for add command
License: MIT Signed-off-by: Dominic Della Valle <ddvpublic@gmail.com>
Dominic Della Valle committed
Nov 2, 2015 at 16:08 UTC
a6eb32b77c3d4d205b9b3a397984efb878d77b4f
4 files changed
+8
-7
commands/cli/parse.go
+2
-1
@@ -5,6 +5,7 @@ import (
5
"fmt"
6
"os"
7
"path"
8
+ "path/filepath"
9
"runtime"
10
"strings"
11
@@ -364,7 +365,7 @@ func appendStdinAsString(args []string, stdin *os.File) ([]string, *os.File, err
365
}
366
367
func appendFile(args []files.File, inputs []string, argDef *cmds.Argument, recursive bool) ([]files.File, []string, error) {
367
- fpath := inputs[0]
368
+ fpath := filepath.ToSlash(filepath.Clean(inputs[0]))
369
370
if fpath == "." {
371
cwd, err := os.Getwd()
commands/files/serialfile.go
+4
-4
@@ -5,7 +5,7 @@ import (
5
"io"
6
"io/ioutil"
7
"os"
8
- fp "path/filepath"
8
+ "path/filepath"
9
"syscall"
10
)
11
@@ -69,8 +69,8 @@ func (f *serialFile) NextFile() (File, error) {
69
f.files = f.files[1:]
70
71
// open the next file
72
- fileName := fp.Join(f.name, stat.Name())
73
- filePath := fp.Join(f.path, stat.Name())
72
+ fileName := filepath.ToSlash(filepath.Join(f.name, stat.Name()))
73
+ filePath := filepath.ToSlash(filepath.Join(f.path, stat.Name()))
74
75
// recursively call the constructor on the next file
76
// if it's a regular file, we will open it as a ReaderFile
@@ -120,7 +120,7 @@ func (f *serialFile) Size() (int64, error) {
120
}
121
122
var du int64
123
- err := fp.Walk(f.FileName(), func(p string, fi os.FileInfo, err error) error {
123
+ err := filepath.Walk(f.FileName(), func(p string, fi os.FileInfo, err error) error {
124
if fi != nil && fi.Mode()&(os.ModeSymlink|os.ModeNamedPipe) == 0 {
125
du += fi.Size()
126
}
core/commands/add.go
+1
-1
@@ -446,7 +446,7 @@ func (params *adder) addDir(file files.File) (*dag.Node, error) {
446
}
447
448
if node != nil {
449
- _, name := path.Split(file.FileName())
449
+ name := path.Base(file.FileName())
450
451
err = tree.AddNodeLink(name, node)
452
if err != nil {
core/corehttp/gateway_handler.go
+1
-1
@@ -174,7 +174,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
174
175
if err == nil {
176
defer dr.Close()
177
- _, name := gopath.Split(urlPath)
177
+ name := gopath.Base(urlPath)
178
http.ServeContent(w, r, name, modtime, dr)
179
return
180
}