Skip to content

Commit

Permalink
Fixing the issue with + in s3 file name while downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
mmendonca3 committed Oct 17, 2017
1 parent 426a188 commit 2290af8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions agent/plugins/downloadcontent/s3resource/s3resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ func (s3 *S3Resource) Download(log log.T, filesys filemanager.FileSystem, destPa
}
log.Info("Downloading S3 artifacts from path - ", s3.Info.Path)

// Change from '+' to '%20' is made as a workaround because s3 uses + for spaces in its URL instead of %20
// This makes the differentiation between '+' and ' ' impossible when we try to manipulate the path of files to download
// Since %20 is the universal escaping for ' ', s3 accepts that as well.
// https://s3.amazonaws.com/aws-executecommand-test/scripts/hello%2Bworld/spaces+file.sh
// new path - https://s3.amazonaws.com/aws-executecommand-test/scripts/hello%2Bworld/spaces%20file.sh
s3.Info.Path = strings.Replace(s3.Info.Path, "+", "%20", -1)

if fileURL, err = url.Parse(s3.Info.Path); err != nil {
return err
}
Expand Down Expand Up @@ -123,6 +130,14 @@ func (s3 *S3Resource) Download(log log.T, filesys filemanager.FileSystem, destPa

bucketURL.Path += "/" + files
input.SourceURL = bucketURL.String()

// When s3 object returns the Path, it has + for '+', and %20 for ' ', because of the workaround above.
// Since we are sending this URL for download, S3 manipulates the + to be a space.
// Change from '+' to '%2B' which is the encoding for '+' so that s3 has to interpret %20 to be a space and %2B
// to be a '+'
// https://s3.amazonaws.com/aws-executecommand-test/scripts/hello+world/spaces%20file.sh
// https://s3.amazonaws.com/aws-executecommand-test/scripts/hello%2Bworld/spaces%20file.sh
input.SourceURL = strings.Replace(input.SourceURL, "+", "%2B", -1)
log.Debug("SourceURL ", input.SourceURL)
if unescapedURL, err = url.QueryUnescape(input.SourceURL); err != nil {
return err
Expand Down

0 comments on commit 2290af8

Please sign in to comment.