From dc553e2e9a0bf8b66d0e175a36de1a9b8f5b6dfe Mon Sep 17 00:00:00 2001 From: Zack Bloom Date: Wed, 9 Dec 2015 10:42:19 -0500 Subject: [PATCH 1/3] Experimental Windows filepath fix --- src/deploy.go | 20 ++++++++++---------- src/utils.go | 9 +++++++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/deploy.go b/src/deploy.go index e821ba8..75ef11d 100644 --- a/src/deploy.go +++ b/src/deploy.go @@ -125,7 +125,7 @@ func uploadFile(bucket *s3.Bucket, reader io.Reader, dest string, includeHash bo } if includeHash { - dest = filepath.Join(hashPrefix, dest) + dest = joinPath(hashPrefix, dest) } log.Printf("Uploading to %s in %s (%s) [%d]\n", dest, bucket.Name, hashPrefix, caching) @@ -355,8 +355,8 @@ func deployHTML(options Options, id string, file HTMLFile) { panic(err) } - permPath := filepath.Join(options.Dest, id, internalPath) - curPath := filepath.Join(options.Dest, internalPath) + permPath := joinPath(options.Dest, id, internalPath) + curPath := joinPath(options.Dest, internalPath) bucket := s3Session.Bucket(options.Bucket) uploadFile(bucket, strings.NewReader(data), permPath, false, FOREVER) @@ -373,7 +373,7 @@ func expandFiles(root string, glob string) []string { if strings.HasPrefix(pattern, "-/") { pattern = pattern[2:] } else { - pattern = filepath.Join(root, pattern) + pattern = joinPath(root, pattern) } list := must(filepath.Glob(pattern)).([]string) @@ -404,7 +404,7 @@ func listFiles(options Options) []*FileRef { files := make([]*FileRef, len(filePaths)) for i, path := range filePaths { - remotePath := filepath.Join(options.Dest, mustString(filepath.Rel(options.Root, path))) + remotePath := joinPath(options.Dest, mustString(filepath.Rel(options.Root, path))) for strings.HasPrefix(remotePath, "../") { remotePath = remotePath[3:] @@ -447,7 +447,7 @@ func extractFileList(options Options, pattern string) (files []string) { parts := strings.Split(pattern, ",") for _, part := range parts { - matches, err := filepath.Glob(filepath.Join(options.Root, part)) + matches, err := filepath.Glob(joinPath(options.Root, part)) if err != nil { panic(err) } @@ -521,11 +521,11 @@ func Deploy(options Options) { for j, path := range paths { var local, remote string if strings.HasPrefix(path, "/") { - local = filepath.Join(options.Root, base, path) - remote = filepath.Join(options.Dest, base, path) + local = joinPath(options.Root, base, path) + remote = joinPath(options.Dest, base, path) } else { - local = filepath.Join(options.Root, rel, base, path) - remote = filepath.Join(options.Dest, rel, base, path) + local = joinPath(options.Root, rel, base, path) + remote = joinPath(options.Dest, rel, base, path) } for strings.HasPrefix(remote, "../") { diff --git a/src/utils.go b/src/utils.go index b44466a..f364f5d 100644 --- a/src/utils.go +++ b/src/utils.go @@ -6,6 +6,8 @@ import ( "io/ioutil" "os" "path/filepath" + "regexp" + "strings" "github.com/imdario/mergo" "github.com/mitchellh/go-homedir" @@ -212,3 +214,10 @@ func copyFile(bucket *s3.Bucket, from string, to string, contentType string, max panic(err) } } + +var pathRe = regexp.MustCompile("/{2,}") + +func joinPath(parts ...string) string { + // Like filepath.Join, but always uses '/' + return pathRe.ReplaceAllLiteralString(strings.Join(parts, "/"), "/") +} From 26ce5210f8644c172e880108ae5511ce0acc1223 Mon Sep 17 00:00:00 2001 From: Giovanni Lanzani Date: Wed, 30 Dec 2015 23:11:02 +0100 Subject: [PATCH 2/3] Remove last usage of filepath.Join This was causing issues on Windows system. The previous commit fixed all the instances of filepath.Join but this one. --- src/utils.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/utils.go b/src/utils.go index f364f5d..4dbd385 100644 --- a/src/utils.go +++ b/src/utils.go @@ -5,7 +5,6 @@ import ( "fmt" "io/ioutil" "os" - "path/filepath" "regexp" "strings" @@ -209,7 +208,7 @@ func copyFile(bucket *s3.Bucket, from string, to string, contentType string, max }, } - _, err := bucket.PutCopy(to, s3.PublicRead, copyOpts, filepath.Join(bucket.Name, from)) + _, err := bucket.PutCopy(to, s3.PublicRead, copyOpts, joinPath(bucket.Name, from)) if err != nil { panic(err) } From d5a788392998d8bae336d7bd58d4715c9d8d1298 Mon Sep 17 00:00:00 2001 From: Zack Bloom Date: Thu, 31 Dec 2015 21:22:02 -0500 Subject: [PATCH 3/3] Fix filepath joining to cleanup paths --- src/utils.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/utils.go b/src/utils.go index 4dbd385..dc97efd 100644 --- a/src/utils.go +++ b/src/utils.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "os" + "path/filepath" "regexp" "strings" @@ -218,5 +219,11 @@ var pathRe = regexp.MustCompile("/{2,}") func joinPath(parts ...string) string { // Like filepath.Join, but always uses '/' - return pathRe.ReplaceAllLiteralString(strings.Join(parts, "/"), "/") + out := filepath.Join(parts...) + + if os.PathSeparator != '/' { + out = strings.Replace(out, string(os.PathSeparator), "/", -1) + } + + return out }