mirror of
https://github.com/minio/minio.git
synced 2025-01-24 13:13:16 -05:00
simplify bucket metadata lookups for versioning/object locking (#17253)
This commit is contained in:
parent
b1b00a5055
commit
fc03be7891
@ -705,7 +705,7 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
}
|
}
|
||||||
if _, ok := bucketMap[bucket]; !ok {
|
if _, ok := bucketMap[bucket]; !ok {
|
||||||
opts := MakeBucketOptions{
|
opts := MakeBucketOptions{
|
||||||
LockEnabled: config.ObjectLockEnabled == "Enabled",
|
LockEnabled: config.Enabled(),
|
||||||
}
|
}
|
||||||
err = objectAPI.MakeBucket(ctx, bucket, opts)
|
err = objectAPI.MakeBucket(ctx, bucket, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -119,6 +119,16 @@ func newBucketMetadata(name string) BucketMetadata {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Versioning returns true if versioning is enabled
|
||||||
|
func (b BucketMetadata) Versioning() bool {
|
||||||
|
return b.LockEnabled || (b.versioningConfig != nil && b.versioningConfig.Enabled()) || (b.objectLockConfig != nil && b.objectLockConfig.Enabled())
|
||||||
|
}
|
||||||
|
|
||||||
|
// ObjectLocking returns true if object locking is enabled
|
||||||
|
func (b BucketMetadata) ObjectLocking() bool {
|
||||||
|
return b.LockEnabled || (b.objectLockConfig != nil && b.objectLockConfig.Enabled())
|
||||||
|
}
|
||||||
|
|
||||||
// SetCreatedAt preserves the CreatedAt time for bucket across sites in site replication. It defaults to
|
// SetCreatedAt preserves the CreatedAt time for bucket across sites in site replication. It defaults to
|
||||||
// creation time of bucket on this cluster in all other cases.
|
// creation time of bucket on this cluster in all other cases.
|
||||||
func (b *BucketMetadata) SetCreatedAt(createdAt time.Time) {
|
func (b *BucketMetadata) SetCreatedAt(createdAt time.Time) {
|
||||||
|
@ -1627,8 +1627,8 @@ func (z *erasureServerPools) GetBucketInfo(ctx context.Context, bucket string, o
|
|||||||
meta, err := globalBucketMetadataSys.Get(bucket)
|
meta, err := globalBucketMetadataSys.Get(bucket)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
bucketInfo.Created = meta.Created
|
bucketInfo.Created = meta.Created
|
||||||
bucketInfo.Versioning = meta.LockEnabled || globalBucketVersioningSys.Enabled(bucket)
|
bucketInfo.Versioning = meta.Versioning()
|
||||||
bucketInfo.ObjectLocking = meta.LockEnabled
|
bucketInfo.ObjectLocking = meta.ObjectLocking()
|
||||||
}
|
}
|
||||||
return bucketInfo, nil
|
return bucketInfo, nil
|
||||||
}
|
}
|
||||||
|
@ -1615,13 +1615,11 @@ func (c *SiteReplicationSys) syncToAllPeers(ctx context.Context) error {
|
|||||||
return errSRBackendIssue(err)
|
return errSRBackendIssue(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var opts MakeBucketOptions
|
opts := MakeBucketOptions{
|
||||||
if meta.objectLockConfig != nil {
|
LockEnabled: meta.ObjectLocking(),
|
||||||
opts.LockEnabled = meta.objectLockConfig.ObjectLockEnabled == "Enabled"
|
CreatedAt: bucketInfo.Created.UTC(),
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.CreatedAt = bucketInfo.Created.UTC()
|
|
||||||
|
|
||||||
// Now call the MakeBucketHook on existing bucket - this will
|
// Now call the MakeBucketHook on existing bucket - this will
|
||||||
// create buckets and replication rules on peer clusters.
|
// create buckets and replication rules on peer clusters.
|
||||||
if err = c.MakeBucketHook(ctx, bucket, opts); err != nil {
|
if err = c.MakeBucketHook(ctx, bucket, opts); err != nil {
|
||||||
|
@ -229,6 +229,11 @@ type Config struct {
|
|||||||
} `xml:"Rule,omitempty"`
|
} `xml:"Rule,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enabled returns true if config.ObjectLockEnabled is set to Enabled
|
||||||
|
func (config *Config) Enabled() bool {
|
||||||
|
return config.ObjectLockEnabled == Enabled
|
||||||
|
}
|
||||||
|
|
||||||
// UnmarshalXML - decodes XML data.
|
// UnmarshalXML - decodes XML data.
|
||||||
func (config *Config) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
func (config *Config) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||||
// Make subtype to avoid recursive UnmarshalXML().
|
// Make subtype to avoid recursive UnmarshalXML().
|
||||||
|
Loading…
x
Reference in New Issue
Block a user