Skip to content

Commit

Permalink
Merge pull request #10 from Othoz/create-property-root-bugifx
Browse files Browse the repository at this point in the history
Create property root bugifx
  • Loading branch information
birnbaum committed Dec 18, 2018
2 parents 5a5f9f0 + ce43770 commit c2ef261
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ Possible types of changes are:
Unreleased
----------

0.4.1 - 18.12.2018
------------------

Fixed
'''''
- Fixed a bug where ``create=True`` in combination with an "empty-ish ``root_path`` like ``""``, ``"."`` or ``"/"`` would create a directory marker.


0.4.0 - 11.12.2018
------------------
Expand All @@ -30,7 +37,6 @@ Added
which means they will raise a ``CreateFailed`` exception if ``root_path`` does not exist



0.3.0 - 20.11.2018
------------------

Expand Down
15 changes: 8 additions & 7 deletions fs_gcsfs/_gcsfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ def __init__(self,
except google.api_core.exceptions.Forbidden as err:
raise CreateFailed("You don't have access to the bucket \"{}\"".format(self._bucket_name)) from err

if create:
root_marker = self._get_blob(forcedir(root_path))
if root_marker is None:
blob = self.bucket.blob(forcedir(root_path))
blob.upload_from_string(b"")
elif strict and self._get_blob(forcedir(root_path)) is None:
raise errors.CreateFailed("Root path \"{}\" does not exist".format(root_path))
if self._prefix != "":
if create:
root_marker = self._get_blob(self._prefix + GCSFS.DELIMITER)
if root_marker is None:
blob = self.bucket.blob(self._prefix + GCSFS.DELIMITER)
blob.upload_from_string(b"")
elif strict and self._get_blob(self._prefix + GCSFS.DELIMITER) is None:
raise errors.CreateFailed("Root path \"{}\" does not exist".format(root_path))

def __repr__(self) -> str:
return _make_repr(
Expand Down
2 changes: 1 addition & 1 deletion fs_gcsfs/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.4.0"
__version__ = "0.4.1"
7 changes: 7 additions & 0 deletions fs_gcsfs/tests/test_gcsfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ def test_listdir_works_on_bucket_as_root_directory(client):
assert directory in result


@pytest.mark.parametrize("root_path", ["", ".", "/"])
def test_create_property_does_not_create_file_if_emptyish_root_path(root_path, client):
"""Regression test for a bug fixed in 0.4.1"""
gcs_fs = GCSFS(bucket_name=TEST_BUCKET, root_path=root_path, client=client, create=True)
assert gcs_fs.bucket.get_blob(root_path + GCSFS.DELIMITER) is None


def test_fix_storage_adds_binary_blobs_with_empty_string_as_directory_marker(bucket, tmp_gcsfs):
# Creating a 'nested' hierarchy of blobs without directory marker
for path in ["foo/test", "foo/bar/test", "foo/baz/test", "foo/bar/egg/test"]:
Expand Down

0 comments on commit c2ef261

Please sign in to comment.