Skip to content

Commit e47e7bf

Browse files
authored
Merge pull request #496 from martindurant/make_bucket
Make bucket for put(recursive)
2 parents a3abba5 + 1ebab8d commit e47e7bf

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

s3fs/core.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -898,13 +898,16 @@ async def _pipe_file(self, path, data, chunksize=50 * 2 ** 20, **kwargs):
898898

899899
async def _put_file(self, lpath, rpath, chunksize=50 * 2 ** 20, **kwargs):
900900
bucket, key, _ = self.split_path(rpath)
901-
if os.path.isdir(lpath) and key:
902-
# don't make remote "directory"
903-
return
901+
if os.path.isdir(lpath):
902+
if key:
903+
# don't make remote "directory"
904+
return
905+
else:
906+
await self._mkdir(lpath)
904907
size = os.path.getsize(lpath)
905908
with open(lpath, "rb") as f0:
906909
if size < min(5 * 2 ** 30, 2 * chunksize):
907-
return await self._call_s3(
910+
await self._call_s3(
908911
"put_object", Bucket=bucket, Key=key, Body=f0, **kwargs
909912
)
910913
else:
@@ -939,7 +942,9 @@ async def _put_file(self, lpath, rpath, chunksize=50 * 2 ** 20, **kwargs):
939942
UploadId=mpu["UploadId"],
940943
MultipartUpload={"Parts": parts},
941944
)
942-
self.invalidate_cache(rpath)
945+
while rpath:
946+
self.invalidate_cache(rpath)
947+
rpath = self._parent(rpath)
943948

944949
async def _get_file(self, rpath, lpath, version_id=None):
945950
bucket, key, vers = self.split_path(rpath)

s3fs/tests/test_s3fs.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,3 +2148,14 @@ def test_list_after_find(s3):
21482148
s3.find("s3://test/2014-01-01.csv")
21492149
after = s3.ls("s3://test")
21502150
assert before == after
2151+
2152+
2153+
def test_upload_recursive_to_bucket(s3, tmpdir):
2154+
# GH#491
2155+
folders = [os.path.join(tmpdir, d) for d in ["outer", "outer/inner"]]
2156+
files = [os.path.join(tmpdir, f) for f in ["outer/afile", "outer/inner/bfile"]]
2157+
for d in folders:
2158+
os.mkdir(d)
2159+
for f in files:
2160+
open(f, "w").write("hello")
2161+
s3.put(folders[0], "newbucket", recursive=True)

0 commit comments

Comments
 (0)