diff --git a/gcsfs/core.py b/gcsfs/core.py index 2978b9b9..7baf881b 100644 --- a/gcsfs/core.py +++ b/gcsfs/core.py @@ -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) diff --git a/gcsfs/tests/test_core.py b/gcsfs/tests/test_core.py index b2de2f91..ebd33c0c 100644 --- a/gcsfs/tests/test_core.py +++ b/gcsfs/tests/test_core.py @@ -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