// SetBucketMetadata - func (fs *fsDriver) SetBucketMetadata(bucket, acl string) error { fs.lock.Lock() defer fs.lock.Unlock() if !drivers.IsValidBucket(bucket) { return iodine.New(drivers.BucketNameInvalid{Bucket: bucket}, nil) } if !drivers.IsValidBucketACL(acl) { return iodine.New(drivers.InvalidACL{ACL: acl}, nil) } // get bucket path bucketDir := filepath.Join(fs.root, bucket) err := os.Chmod(bucketDir, aclToPerm(acl)) if err != nil { return iodine.New(err, nil) } return nil }
// CreateBucket creates a new bucket func (d donutDriver) CreateBucket(bucketName, acl string) error { d.lock.Lock() defer d.lock.Unlock() if len(d.storedBuckets) == totalBuckets { return iodine.New(drivers.TooManyBuckets{Bucket: bucketName}, nil) } if d.donut == nil { return iodine.New(drivers.InternalError{}, nil) } if !drivers.IsValidBucketACL(acl) { return iodine.New(drivers.InvalidACL{ACL: acl}, nil) } if drivers.IsValidBucket(bucketName) { if strings.TrimSpace(acl) == "" { acl = "private" } if err := d.donut.MakeBucket(bucketName, acl); err != nil { switch iodine.ToError(err).(type) { case donut.BucketExists: return iodine.New(drivers.BucketExists{Bucket: bucketName}, nil) } return iodine.New(err, nil) } var newBucket = storedBucket{} newBucket.objectMetadata = make(map[string]drivers.ObjectMetadata) newBucket.multiPartSession = make(map[string]multiPartSession) newBucket.partMetadata = make(map[string]drivers.PartMetadata) metadata, err := d.donut.GetBucketMetadata(bucketName) if err != nil { return iodine.New(err, nil) } newBucket.bucketMetadata = drivers.BucketMetadata{ Name: metadata.Name, Created: metadata.Created, ACL: drivers.BucketACL(metadata.ACL), } d.storedBuckets[bucketName] = newBucket return nil } return iodine.New(drivers.BucketNameInvalid{Bucket: bucketName}, nil) }
// CreateBucket creates a new bucket func (d donutDriver) CreateBucket(bucketName, acl string) error { if d.donut == nil { return iodine.New(drivers.InternalError{}, nil) } if !drivers.IsValidBucketACL(acl) { return iodine.New(drivers.InvalidACL{ACL: acl}, nil) } if drivers.IsValidBucket(bucketName) && !strings.Contains(bucketName, ".") { if strings.TrimSpace(acl) == "" { acl = "private" } if err := d.donut.MakeBucket(bucketName, acl); err != nil { err = iodine.ToError(err) if err.Error() == "bucket exists" { return iodine.New(drivers.BucketExists{Bucket: bucketName}, nil) } return err } return nil } return iodine.New(drivers.BucketNameInvalid{Bucket: bucketName}, nil) }
// CreateBucket - create bucket in cache func (cache *cacheDriver) CreateBucket(bucketName, acl string) error { cache.lock.RLock() if len(cache.storedBuckets) == totalBuckets { cache.lock.RUnlock() return iodine.New(drivers.TooManyBuckets{Bucket: bucketName}, nil) } if !drivers.IsValidBucket(bucketName) { cache.lock.RUnlock() return iodine.New(drivers.BucketNameInvalid{Bucket: bucketName}, nil) } if !drivers.IsValidBucketACL(acl) { cache.lock.RUnlock() return iodine.New(drivers.InvalidACL{ACL: acl}, nil) } if _, ok := cache.storedBuckets[bucketName]; ok == true { cache.lock.RUnlock() return iodine.New(drivers.BucketExists{Bucket: bucketName}, nil) } cache.lock.RUnlock() if strings.TrimSpace(acl) == "" { // default is private acl = "private" } var newBucket = storedBucket{} newBucket.objectMetadata = make(map[string]drivers.ObjectMetadata) newBucket.multiPartSession = make(map[string]multiPartSession) newBucket.partMetadata = make(map[string]drivers.PartMetadata) newBucket.bucketMetadata = drivers.BucketMetadata{} newBucket.bucketMetadata.Name = bucketName newBucket.bucketMetadata.Created = time.Now().UTC() newBucket.bucketMetadata.ACL = drivers.BucketACL(acl) cache.lock.Lock() cache.storedBuckets[bucketName] = newBucket cache.lock.Unlock() return nil }
// CreateBucket creates a new bucket func (d donutDriver) CreateBucket(bucketName, acl string) error { d.lock.Lock() defer d.lock.Unlock() if d.donut == nil { return iodine.New(drivers.InternalError{}, nil) } if !drivers.IsValidBucketACL(acl) { return iodine.New(drivers.InvalidACL{ACL: acl}, nil) } if drivers.IsValidBucket(bucketName) && !strings.Contains(bucketName, ".") { if strings.TrimSpace(acl) == "" { acl = "private" } if err := d.donut.MakeBucket(bucketName, acl); err != nil { switch iodine.ToError(err).(type) { case donut.BucketExists: return iodine.New(drivers.BucketExists{Bucket: bucketName}, nil) } return iodine.New(err, nil) } return nil } return iodine.New(drivers.BucketNameInvalid{Bucket: bucketName}, nil) }