MCPcopy
hub / github.com/rclone/rclone / makeBucket

Method makeBucket

backend/s3/s3.go:2841–2882  ·  view source on GitHub ↗

makeBucket creates the bucket if it doesn't exist

(ctx context.Context, bucket string)

Source from the content-addressed store, hash-verified

2839
2840// makeBucket creates the bucket if it doesn't exist
2841func (f *Fs) makeBucket(ctx context.Context, bucket string) error {
2842 if f.opt.NoCheckBucket {
2843 return nil
2844 }
2845 return f.cache.Create(bucket, func() error {
2846 req := s3.CreateBucketInput{
2847 Bucket: &bucket,
2848 ACL: types.BucketCannedACL(f.opt.BucketACL),
2849 ObjectLockEnabledForBucket: &f.opt.BucketObjectLockEnabled,
2850 }
2851 if f.opt.LocationConstraint != "" {
2852 req.CreateBucketConfiguration = &types.CreateBucketConfiguration{
2853 LocationConstraint: types.BucketLocationConstraint(f.opt.LocationConstraint),
2854 }
2855 }
2856 err := f.pacer.Call(func() (bool, error) {
2857 _, err := f.c.CreateBucket(ctx, &req)
2858 return f.shouldRetry(ctx, err)
2859 })
2860 if err == nil {
2861 fs.Infof(f, "Bucket %q created with ACL %q", bucket, f.opt.BucketACL)
2862 }
2863 var awsErr smithy.APIError
2864 if errors.As(err, &awsErr) {
2865 switch awsErr.ErrorCode() {
2866 case "BucketAlreadyOwnedByYou":
2867 err = nil
2868 case "BucketAlreadyExists", "BucketNameUnavailable":
2869 if f.opt.UseAlreadyExists.Value {
2870 // We can trust BucketAlreadyExists to mean not owned by us, so make it non retriable
2871 err = fserrors.NoRetryError(err)
2872 } else {
2873 // We can't trust BucketAlreadyExists to mean not owned by us, so ignore it
2874 err = nil
2875 }
2876 }
2877 }
2878 return err
2879 }, func() (bool, error) {
2880 return f.bucketExists(ctx, bucket)
2881 })
2882}
2883
2884// Rmdir deletes the bucket if the fs is at the root
2885//

Callers 1

MkdirMethod · 0.95

Calls 7

shouldRetryMethod · 0.95
bucketExistsMethod · 0.95
InfofFunction · 0.92
NoRetryErrorFunction · 0.92
CreateBucketMethod · 0.80
CreateMethod · 0.65
CallMethod · 0.45

Tested by

no test coverage detected