Skip to content

Commit

Permalink
Merge branch 'filepath'
Browse files Browse the repository at this point in the history
Conflicts:
	src/deploy.go
  • Loading branch information
zackbloom committed Jan 1, 2016
2 parents af1645f + d5a7883 commit 5fabd2c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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:]
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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, path)
remote = filepath.Join(options.Dest, path)
local = joinPath(options.Root, path)
remote = joinPath(options.Dest, 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, "../") {
Expand Down
17 changes: 16 additions & 1 deletion src/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/imdario/mergo"
"github.com/mitchellh/go-homedir"
Expand Down Expand Up @@ -207,8 +209,21 @@ 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)
}
}

var pathRe = regexp.MustCompile("/{2,}")

func joinPath(parts ...string) string {
// Like filepath.Join, but always uses '/'
out := filepath.Join(parts...)

if os.PathSeparator != '/' {
out = strings.Replace(out, string(os.PathSeparator), "/", -1)
}

return out
}

0 comments on commit 5fabd2c

Please sign in to comment.