Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions s3fs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,15 @@ def put(self, filename, path, **kwargs):
f2.write(data)

def mkdir(self, path, acl="", **kwargs):
""" Make new bucket or empty key """
""" Make new bucket or empty key

Parameters
----------
acl: str
ACL to set when creating
region_name : str
region in which the bucket should be created
"""
acl = acl or self.s3_additional_kwargs.get('ACL', '')
self.touch(path, acl=acl, **kwargs)

Expand Down Expand Up @@ -961,7 +969,14 @@ def touch(self, path, acl="", **kwargs):
if acl and acl not in buck_acls:
raise ValueError('ACL not in %s', buck_acls)
try:
self.s3.create_bucket(Bucket=bucket, ACL=acl)
params = {"Bucket": bucket, 'ACL': acl}
region_name = (kwargs.get("region_name", None) or
self.client_kwargs.get("region_name", None))
if region_name:
params['CreateBucketConfiguration'] = {
'LocationConstraint': region_name
}
self.s3.create_bucket(**params)
self.invalidate_cache('')
self.invalidate_cache(bucket)
except (ClientError, ParamValidationError):
Expand Down
25 changes: 25 additions & 0 deletions s3fs/tests/test_s3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,31 @@ def test_rmdir(s3):
assert bucket not in s3.ls('/')


def test_mkdir(s3):
bucket = 'test1_bucket'
s3.mkdir(bucket)
assert bucket in s3.ls('/')


def test_mkdir_region_name(s3):
bucket = 'test1_bucket'
s3.mkdir(bucket, region_name="eu-central-1")
assert bucket in s3.ls('/')


def test_mkdir_client_region_name():
bucket = 'test1_bucket'
try:
m = moto.mock_s3()
m.start()
s3 = S3FileSystem(anon=False, client_kwargs={"region_name":
"eu-central-1"})
s3.mkdir(bucket)
assert bucket in s3.ls('/')
finally:
m.stop()


def test_bulk_delete(s3):
with pytest.raises((OSError, IOError)):
s3.bulk_delete(['nonexistent/file'])
Expand Down