setBucketMetadata: Fix a deadlock.

master
Harshavardhana 9 years ago
parent c922dd6fbd
commit 8bf1045645
  1. 4
      pkg/fs/fs-bucket.go
  2. 10
      pkg/fs/postpolicyform.go
  3. 2
      pkg/mimedb/db.go
  4. 4
      pkg/mimedb/util/gen-db.go

@ -223,8 +223,6 @@ func (fs Filesystem) GetBucketMetadata(bucket string) (BucketMetadata, *probe.Er
// SetBucketMetadata - set bucket metadata.
func (fs Filesystem) SetBucketMetadata(bucket string, metadata map[string]string) *probe.Error {
fs.rwLock.Lock()
defer fs.rwLock.Unlock()
// Input validation.
if !IsValidBucketName(bucket) {
return probe.NewError(BucketNameInvalid{Bucket: bucket})
@ -247,7 +245,9 @@ func (fs Filesystem) SetBucketMetadata(bucket string, metadata map[string]string
}
return probe.NewError(e)
}
fs.rwLock.RLock()
bucketMetadata, ok := fs.buckets.Metadata[bucket]
fs.rwLock.RUnlock()
if !ok {
bucketMetadata = &BucketMetadata{}
bucketMetadata.Name = fi.Name()

@ -100,7 +100,7 @@ func ParsePostPolicyForm(policy string) (PostPolicyForm, *probe.Error) {
for k, v := range condt {
if !isString(v) { // Pre-check value type.
// All values must be of type string.
return parsedPolicy, probe.NewError(fmt.Errorf("Unknown type ‘%s’ of conditional field value ‘%s’ found in POST policy form.",
return parsedPolicy, probe.NewError(fmt.Errorf("Unknown type %s of conditional field value %s found in POST policy form.",
reflect.TypeOf(condt).String(), condt))
}
// {"acl": "public-read" } is an alternate way to indicate - [ "eq", "$acl", "public-read" ]
@ -115,7 +115,7 @@ func ParsePostPolicyForm(policy string) (PostPolicyForm, *probe.Error) {
}
case []interface{}: // Handle array types.
if len(condt) != 3 { // Return error if we have insufficient elements.
return parsedPolicy, probe.NewError(fmt.Errorf("Malformed conditional fields ‘%s’ of type ‘%s’ found in POST policy form.",
return parsedPolicy, probe.NewError(fmt.Errorf("Malformed conditional fields %s of type %s found in POST policy form.",
condt, reflect.TypeOf(condt).String()))
}
switch toString(condt[0]) {
@ -123,7 +123,7 @@ func ParsePostPolicyForm(policy string) (PostPolicyForm, *probe.Error) {
for _, v := range condt { // Pre-check all values for type.
if !isString(v) {
// All values must be of type string.
return parsedPolicy, probe.NewError(fmt.Errorf("Unknown type ‘%s’ of conditional field value ‘%s’ found in POST policy form.",
return parsedPolicy, probe.NewError(fmt.Errorf("Unknown type %s of conditional field value %s found in POST policy form.",
reflect.TypeOf(condt).String(), condt))
}
}
@ -145,11 +145,11 @@ func ParsePostPolicyForm(policy string) (PostPolicyForm, *probe.Error) {
}
default:
// Condition should be valid.
return parsedPolicy, probe.NewError(fmt.Errorf("Unknown type ‘%s’ of conditional field value ‘%s’ found in POST policy form.",
return parsedPolicy, probe.NewError(fmt.Errorf("Unknown type %s of conditional field value %s found in POST policy form.",
reflect.TypeOf(condt).String(), condt))
}
default:
return parsedPolicy, probe.NewError(fmt.Errorf("Unknown field ‘%s’ of type ‘%s’ found in POST policy form.",
return parsedPolicy, probe.NewError(fmt.Errorf("Unknown field %s of type %s found in POST policy form.",
condt, reflect.TypeOf(condt).String()))
}
}

@ -19,7 +19,7 @@
// Definitions are imported from NodeJS mime-db project under MIT license.
package mimedb
// Mime is a collection of mime types with extension as key and content-type as value.
// DB - Mime is a collection of mime types with extension as key and content-type as value.
var DB = map[string]struct {
ContentType string
Compressible bool

@ -49,7 +49,7 @@ const progTempl = `// DO NOT EDIT THIS FILE. IT IS AUTO-GENERATED BY "gen-db.go"
// Definitions are imported from NodeJS mime-db project under MIT license.
package mimedb
// Mime is a collection of mime types with extension as key and content-type as value.
// DB - Mime is a collection of mime types with extension as key and content-type as value.
var DB = map[string]struct {
ContentType string
Compressible bool
@ -68,8 +68,6 @@ type mimeEntry struct {
type mimeDB map[string]mimeEntry
var ()
// JSON data from gobindata and parse them into extDB.
func convertDB(jsonFile string) (mimeDB, error) {
// Structure of JSON data from mime-db project.

Loading…
Cancel
Save