makeBucket creates the bucket if it doesn't exist
(ctx context.Context, bucket string)
| 2839 | |
| 2840 | // makeBucket creates the bucket if it doesn't exist |
| 2841 | func (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 | // |
no test coverage detected