Use convenience functions for url.Values over looping through keys, fix a bug in listObjectParts()

master
Harshavardhana 10 years ago
parent 62f20c0f79
commit b48b7f51ef
  1. 11
      pkg/api/api_object_handlers.go
  2. 35
      pkg/api/resources.go
  3. 5
      pkg/storage/drivers/memory/memory.go

@ -305,15 +305,8 @@ func (server *minioAPI) putObjectPartHandler(w http.ResponseWriter, req *http.Re
bucket := vars["bucket"]
object := vars["object"]
var uploadID, partIDString string
for key, value := range req.URL.Query() {
switch true {
case key == "uploadId":
uploadID = value[0]
case key == "partNumber":
partIDString = value[0]
}
}
uploadID := req.URL.Query().Get("uploadId")
partIDString := req.URL.Query().Get("partNumber")
partID, err := strconv.Atoi(partIDString)
if err != nil {

@ -25,37 +25,20 @@ import (
// parse bucket url queries
func getBucketResources(values url.Values) (v drivers.BucketResourcesMetadata) {
for key, value := range values {
switch true {
case key == "prefix":
v.Prefix = value[0]
case key == "marker":
v.Marker = value[0]
case key == "max-keys":
v.Maxkeys, _ = strconv.Atoi(value[0])
case key == "delimiter":
v.Delimiter = value[0]
case key == "encoding-type":
v.EncodingType = value[0]
}
}
v.Prefix = values.Get("prefix")
v.Marker = values.Get("marker")
v.Maxkeys, _ = strconv.Atoi(values.Get("max-keys"))
v.Delimiter = values.Get("delimiter")
v.EncodingType = values.Get("encoding-type")
return
}
// parse object url queries
func getObjectResources(values url.Values) (v drivers.ObjectResourcesMetadata) {
for key, value := range values {
switch true {
case key == "uploadId":
v.UploadID = value[0]
case key == "part-number-marker":
v.PartNumberMarker, _ = strconv.Atoi(value[0])
case key == "max-parts":
v.MaxParts, _ = strconv.Atoi(value[0])
case key == "encoding-type":
v.EncodingType = value[0]
}
}
v.UploadID = values.Get("uploadId")
v.PartNumberMarker, _ = strconv.Atoi(values.Get("part-number-marker"))
v.MaxParts, _ = strconv.Atoi(values.Get("max-parts"))
v.EncodingType = values.Get("encoding-type")
return
}

@ -299,7 +299,7 @@ func (memory *memoryDriver) createObject(bucket, key, contentType, expectedMD5Su
memory.lock.Lock()
memoryObject := make(map[string]drivers.ObjectMetadata)
switch {
case len(memory.storedBuckets[bucket].objectMetadata) == 0:
case len(storedBucket.objectMetadata) == 0:
storedBucket.objectMetadata = memoryObject
storedBucket.objectMetadata[objectKey] = newObject
default:
@ -591,6 +591,7 @@ func (memory *memoryDriver) CreateObjectPart(bucket, key, uploadID string, partI
multiPartSession := storedBucket.multiPartSession[key]
multiPartSession.totalParts++
storedBucket.multiPartSession[key] = multiPartSession
return etag, nil
}
@ -715,7 +716,7 @@ func (memory *memoryDriver) ListObjectParts(bucket, key string, resources driver
objectResourcesMetadata.NextPartNumberMarker = i
return objectResourcesMetadata, nil
}
object, ok := storedBucket.objectMetadata[resources.Bucket+"/"+getMultipartKey(resources.Key, resources.UploadID, i)]
object, ok := storedBucket.objectMetadata[bucket+"/"+getMultipartKey(key, resources.UploadID, i)]
if !ok {
return drivers.ObjectResourcesMetadata{}, iodine.New(errors.New("missing part: "+strconv.Itoa(i)), nil)
}

Loading…
Cancel
Save