@ -230,45 +230,27 @@ func (fs Filesystem) GetBucketMetadata(bucket string) (BucketMetadata, *probe.Er
// SetBucketMetadata - set bucket metadata.
// SetBucketMetadata - set bucket metadata.
func ( fs Filesystem ) SetBucketMetadata ( bucket string , metadata map [ string ] string ) * probe . Error {
func ( fs Filesystem ) SetBucketMetadata ( bucket string , metadata map [ string ] string ) * probe . Error {
// Input validation.
bucketMetadata , err := fs . GetBucketMetadata ( bucket )
if ! IsValidBucketName ( bucket ) {
if err != nil {
return prob e. NewE rror ( BucketNameInvalid { Bucket : bucket } )
return err
}
}
// Save the acl.
// Save the acl.
acl := metadata [ "acl" ]
acl := metadata [ "acl" ]
if ! IsValidBucketACL ( acl ) {
if ! IsValidBucketACL ( acl ) {
return probe . NewError ( InvalidACL { ACL : acl } )
return probe . NewError ( InvalidACL { ACL : acl } )
}
} else if acl == "" {
if acl == "" {
acl = "private"
acl = "private"
}
}
bucket = fs . denormalizeBucket ( bucket )
bucketDir := filepath . Join ( fs . path , bucket )
fi , e := os . Stat ( bucketDir )
if e != nil {
// Check if bucket exists.
if os . IsNotExist ( e ) {
return probe . NewError ( BucketNotFound { Bucket : bucket } )
}
return probe . NewError ( e )
}
// Critical region handle read lock.
fs . rwLock . RLock ( )
bucketMetadata , ok := fs . buckets . Metadata [ bucket ]
fs . rwLock . RUnlock ( )
if ! ok {
bucketMetadata = & BucketMetadata { }
bucketMetadata . Name = fi . Name ( )
bucketMetadata . Created = fi . ModTime ( )
}
bucketMetadata . ACL = BucketACL ( acl )
bucketMetadata . ACL = BucketACL ( acl )
bucket = fs . denormalizeBucket ( bucket )
// Critical region handle write lock.
// Critical region handle write lock.
fs . rwLock . Lock ( )
fs . rwLock . Lock ( )
defer fs . rwLock . Unlock ( )
defer fs . rwLock . Unlock ( )
fs . buckets . Metadata [ bucket ] = bucketMetadata
fs . buckets . Metadata [ bucket ] = & bucketMetadata
if err := saveBucketsMetadata ( * fs . buckets ) ; err != nil {
if err := saveBucketsMetadata ( * fs . buckets ) ; err != nil {
return err . Trace ( bucket )
return err . Trace ( bucket )
}
}