Skip to content

Commit b0455a5

Browse files
committed
Create directory if it doesn not exist in mapping
1 parent 7790640 commit b0455a5

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

s3fs/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ def bulk_delete(self, pathlist):
463463
pathlist : listof strings
464464
The keys to remove, must all be in the same bucket.
465465
"""
466+
if not pathlist:
467+
return
466468
buckets = {split_path(path)[0] for path in pathlist}
467469
if len(buckets) > 1:
468470
raise ValueError("Bulk delete files should refer to only one bucket")

s3fs/mapping.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class S3Map(MutableMapping):
3333
def __init__(self, root, s3=None, check=False):
3434
self.s3 = s3 or S3FileSystem.current()
3535
self.root = root
36+
if not os.path.exists(root):
37+
self.s3.mkdir(root)
3638
if check:
3739
self.s3.touch(root+'/a')
3840
self.s3.rm(root+'/a')

s3fs/tests/test_mapping.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,11 @@ def test_bytearray(s3):
9191
d['x'] = bytearray(b'123')
9292

9393
assert d['x'] == b'123'
94+
95+
96+
def test_new_bucket(s3):
97+
d = S3Map('new-bucket', s3)
98+
assert not d
99+
100+
d = S3Map('new-bucket/new-directory', s3)
101+
assert not d

0 commit comments

Comments
 (0)