Skip to content

Commit

Permalink
Escape the special char in name correctly. As per the AWS documentati…
Browse files Browse the repository at this point in the history
…on, CopyRequest is sending request param and it advised to URLEncode the source name. Using the url.QueryEscape to encode the name instead of urlPahEscape since it does not cover all special char.
  • Loading branch information
skuppa authored and kahing committed Nov 3, 2022
1 parent 5661a83 commit 5ae08c0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
4 changes: 2 additions & 2 deletions internal/backend_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func (s *S3Backend) mpuCopyPart(from string, to string, mpuId string, bytes stri
params := &s3.UploadPartCopyInput{
Bucket: &s.bucket,
Key: &to,
CopySource: aws.String(pathEscape(from)),
CopySource: aws.String(url.QueryEscape(from)),
UploadId: &mpuId,
CopySourceRange: &bytes,
CopySourceIfMatch: srcEtag,
Expand Down Expand Up @@ -671,7 +671,7 @@ func (s *S3Backend) CopyBlob(param *CopyBlobInput) (*CopyBlobOutput, error) {

params := &s3.CopyObjectInput{
Bucket: &s.bucket,
CopySource: aws.String(pathEscape(from)),
CopySource: aws.String(url.QueryEscape(from)),
Key: &param.Destination,
StorageClass: param.StorageClass,
ContentType: s.flags.GetMimeType(param.Destination),
Expand Down
7 changes: 0 additions & 7 deletions internal/goofys.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,13 +574,6 @@ func mapAwsError(err error) error {
}
}

// note that this is NOT the same as url.PathEscape in golang 1.8,
// as this preserves / and url.PathEscape converts / to %2F
func pathEscape(path string) string {
u := url.URL{Path: path}
return u.EscapedPath()
}

func (fs *Goofys) allocateInodeId() (id fuseops.InodeID) {
id = fs.nextInodeID
fs.nextInodeID++
Expand Down
26 changes: 26 additions & 0 deletions internal/goofys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,32 @@ func (s *GoofysTest) TestCreateFiles(t *C) {
defer resp.Body.Close()
}

func (s *GoofysTest) TestRenameWithSpecialChar(t *C) {
fileName := "foo+"
s.testWriteFile(t, fileName, 1, 128*1024)

inode, err := s.getRoot(t).LookUp(fileName)
t.Assert(err, IsNil)

fh, err := inode.OpenFile(fuseops.OpMetadata{uint32(os.Getpid())})
t.Assert(err, IsNil)

err = fh.FlushFile()
t.Assert(err, IsNil)

resp, err := s.cloud.GetBlob(&GetBlobInput{Key: fileName})
t.Assert(err, IsNil)
// ADLv1 doesn't return size when we do a GET
if _, adlv1 := s.cloud.(*ADLv1); !adlv1 {
t.Assert(resp.HeadBlobOutput.Size, Equals, uint64(1))
}
defer resp.Body.Close()

root := s.getRoot(t)
err = root.Rename(fileName, root, "foo")
t.Assert(err, IsNil)
}

func (s *GoofysTest) TestUnlink(t *C) {
fileName := "file1"

Expand Down

0 comments on commit 5ae08c0

Please sign in to comment.