Skip to content

Commit

Permalink
_get_file: fix makedirs call when the lpath is relative and in the wo…
Browse files Browse the repository at this point in the history
…rking directory (#618)
  • Loading branch information
skshetry committed Apr 11, 2024
1 parent 0e113eb commit 17e649a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion gcsfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,8 @@ async def _get_file_request(
callback.set_size(size)

checker = get_consistency_checker(consistency)
os.makedirs(os.path.dirname(lpath), exist_ok=True)
lparent = os.path.dirname(lpath) or os.curdir
os.makedirs(lparent, exist_ok=True)
with open(lpath, "wb") as f2:
while True:
data = await r.content.read(4096 * 32)
Expand Down
13 changes: 13 additions & 0 deletions gcsfs/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,19 @@ def test_get_put_file_in_dir(protocol, gcs):
assert gcs.cat(protocol + TEST_BUCKET + "/temp_dir/accounts.1.json") == data1


@pytest.mark.parametrize("protocol", ["", "gs://", "gcs://"])
def test_get_file_to_current_working_directory(monkeypatch, protocol, gcs):
fn = protocol + TEST_BUCKET + "/temp"
gcs.pipe(fn, b"hello world")

with tempdir() as dn:
os.makedirs(dn)
monkeypatch.chdir(dn)
gcs.get_file(fn, "temp")
with open("temp", mode="rb") as f:
assert f.read() == b"hello world"


def test_special_characters_filename(gcs: GCSFileSystem):
special_filename = """'!"`#$%&'()+,-.<=>?@[]^_{}~/'"""
full_path = TEST_BUCKET + "/" + special_filename
Expand Down

0 comments on commit 17e649a

Please sign in to comment.