multipart: NewMultipartUpload shouldn't return empty UploadID

Existing code
```
{
  if os.IsNotExist(e) {
       e = os.MkdirAll(objectDir, 0700)
       if e != nil {
            return "", probe.NewError(e)
       }
  }
  return "", probe.NewError(e)  ---> Error was here.
}
```
For a successful 'MkdirAll' it would still return an empty uploadID,
but the 'error' would be nil. This would succeed the request but
client would fail.

Fix is to re-arrange the logic. Thanks to Alexander Neumann @fd0, for
reporting this problem.
This commit is contained in:
Harshavardhana
2016-01-26 14:57:46 -08:00
parent 67a70eb6d6
commit 2e311168ee
2 changed files with 30 additions and 7 deletions

View File

@@ -173,13 +173,13 @@ func (fs Filesystem) NewMultipartUpload(bucket, object string) (string, *probe.E
objectPath := filepath.Join(bucketPath, object)
objectDir := filepath.Dir(objectPath)
if _, e := os.Stat(objectDir); e != nil {
if os.IsNotExist(e) {
e = os.MkdirAll(objectDir, 0700)
if e != nil {
return "", probe.NewError(e)
}
if !os.IsNotExist(e) {
return "", probe.NewError(e)
}
e = os.MkdirAll(objectDir, 0700)
if e != nil {
return "", probe.NewError(e)
}
return "", probe.NewError(e)
}
id := []byte(strconv.FormatInt(rand.Int63(), 10) + bucket + object + time.Now().String())
@@ -192,7 +192,7 @@ func (fs Filesystem) NewMultipartUpload(bucket, object string) (string, *probe.E
}
defer multiPartfile.Close()
mpartSession := new(MultipartSession)
mpartSession := &MultipartSession{}
mpartSession.TotalParts = 0
mpartSession.UploadID = uploadID
mpartSession.Initiated = time.Now().UTC()