Skip to content

GH-49949: [C++][S3] Don't call HeadBucket when creating directories - #50793

Open
goel-skd wants to merge 3 commits into
apache:mainfrom
goel-skd:gh-49949-s3fs-createdir-headbucket
Open

GH-49949: [C++][S3] Don't call HeadBucket when creating directories#50793
goel-skd wants to merge 3 commits into
apache:mainfrom
goel-skd:gh-49949-s3fs-createdir-headbucket

Conversation

@goel-skd

@goel-skd goel-skd commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

CreateDir(..., recursive=true) calls HeadBucket to decide whether the bucket needs creating. Credentials scoped to a prefix in the bucket are denied that call, so the directory creation fails even though the caller can write there.

What changes are included in this PR?

Only call HeadBucket when allow_bucket_creation is on. There is nothing to do with the answer otherwise, and a missing bucket still fails when the directory entry is written.

Are these changes tested?

Yes. A new test sets a bucket policy granting anonymous access to a single prefix, which leaves HeadBucket denied, then creates a directory under that prefix. It fails with the reported error without the fix. The test is skipped on MinGW, where the AWS SDK's PutBucketPolicyRequest.h marks an inline definition with AWS_S3_API (__declspec(dllimport)) and GCC rejects it.

Are there any user-facing changes?

With allow_bucket_creation off and a bucket that does not exist, the error now comes from PutObject instead of Bucket 'x' not found. To create buckets, enable the allow_bucket_creation option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant