From a6eb32b77c3d4d205b9b3a397984efb878d77b4f Mon Sep 17 00:00:00 2001 From: Dominic Della Valle Date: Mon, 2 Nov 2015 16:08:39 -0500 Subject: [PATCH] Fix path parsing for add command License: MIT Signed-off-by: Dominic Della Valle --- commands/cli/parse.go | 3 ++- commands/files/serialfile.go | 8 ++++---- core/commands/add.go | 2 +- core/corehttp/gateway_handler.go | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/commands/cli/parse.go b/commands/cli/parse.go index ea12881ec..9fbda2583 100644 --- a/commands/cli/parse.go +++ b/commands/cli/parse.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path" + "path/filepath" "runtime" "strings" @@ -364,7 +365,7 @@ func appendStdinAsString(args []string, stdin *os.File) ([]string, *os.File, err } func appendFile(args []files.File, inputs []string, argDef *cmds.Argument, recursive bool) ([]files.File, []string, error) { - fpath := inputs[0] + fpath := filepath.ToSlash(filepath.Clean(inputs[0])) if fpath == "." { cwd, err := os.Getwd() diff --git a/commands/files/serialfile.go b/commands/files/serialfile.go index b43869a4d..c48a324a7 100644 --- a/commands/files/serialfile.go +++ b/commands/files/serialfile.go @@ -5,7 +5,7 @@ import ( "io" "io/ioutil" "os" - fp "path/filepath" + "path/filepath" "syscall" ) @@ -69,8 +69,8 @@ func (f *serialFile) NextFile() (File, error) { f.files = f.files[1:] // open the next file - fileName := fp.Join(f.name, stat.Name()) - filePath := fp.Join(f.path, stat.Name()) + fileName := filepath.ToSlash(filepath.Join(f.name, stat.Name())) + filePath := filepath.ToSlash(filepath.Join(f.path, stat.Name())) // recursively call the constructor on the next file // if it's a regular file, we will open it as a ReaderFile @@ -120,7 +120,7 @@ func (f *serialFile) Size() (int64, error) { } var du int64 - err := fp.Walk(f.FileName(), func(p string, fi os.FileInfo, err error) error { + err := filepath.Walk(f.FileName(), func(p string, fi os.FileInfo, err error) error { if fi != nil && fi.Mode()&(os.ModeSymlink|os.ModeNamedPipe) == 0 { du += fi.Size() } diff --git a/core/commands/add.go b/core/commands/add.go index a594f90f0..24361f972 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -446,7 +446,7 @@ func (params *adder) addDir(file files.File) (*dag.Node, error) { } if node != nil { - _, name := path.Split(file.FileName()) + name := path.Base(file.FileName()) err = tree.AddNodeLink(name, node) if err != nil { diff --git a/core/corehttp/gateway_handler.go b/core/corehttp/gateway_handler.go index 8cb6dc0f8..509e751de 100644 --- a/core/corehttp/gateway_handler.go +++ b/core/corehttp/gateway_handler.go @@ -174,7 +174,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request if err == nil { defer dr.Close() - _, name := gopath.Split(urlPath) + name := gopath.Base(urlPath) http.ServeContent(w, r, name, modtime, dr) return }