From ca107a154cb6bd21dc498d3283c893a95274c930 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 7 Aug 2015 12:08:49 -0700 Subject: [PATCH] Handle virtual bucket style urls too --- share-main.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/share-main.go b/share-main.go index 8aa427eb..5ef098db 100644 --- a/share-main.go +++ b/share-main.go @@ -19,6 +19,7 @@ package main import ( "errors" "fmt" + "path/filepath" "strings" "time" @@ -77,7 +78,16 @@ func runShareCmd(ctx *cli.Context) { // if recursive strip off the "..." newTargetURL := stripRecursiveURL(targetURL) Fatal(doShareCmd(newTargetURL, isURLRecursive(targetURL), expires)) +} +func getNewTargetURL(targetParser *client.URL, name string) string { + match, _ := filepath.Match("*.s3*.amazonaws.com", targetParser.Host) + if match { + targetParser.Path = string(targetParser.Separator) + name + } else { + targetParser.Path = string(targetParser.Separator) + path2Bucket(targetParser) + string(targetParser.Separator) + name + } + return targetParser.String() } // doShareCmd share files from target @@ -96,9 +106,7 @@ func doShareCmd(targetURL string, recursive bool, expires time.Duration) *probe. if contentCh.Err != nil { return contentCh.Err.Trace() } - targetParser := clnt.URL() - targetParser.Path = path2Bucket(targetParser) + string(targetParser.Separator) + contentCh.Content.Name - newClnt, err := url2Client(targetParser.String()) + newClnt, err := url2Client(getNewTargetURL(clnt.URL(), contentCh.Content.Name)) if err != nil { return err.Trace() }