Skip to content

Commit

Permalink
don't crash when creating multi-layer directories (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
isidentical authored Feb 8, 2021
1 parent a522077 commit 749cd9d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gdrivefs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def mkdir(self, path, create_parents=True, **kwargs):
if create_parents and self._parent(path):
self.makedirs(self._parent(path), exist_ok=True)
parent_id = self.path_to_file_id(self._parent(path))
meta = {"name": path.split("/", 1)[-1],
meta = {"name": path.rstrip("/").rsplit("/", 1)[-1],
'mimeType': DIR_MIME_TYPE,
"parents": [parent_id]}
self.service.create(body=meta).execute()
Expand Down
15 changes: 14 additions & 1 deletion gdrivefs/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def creds():
except IOError:
pass


def test_simple(creds):
fs = gdrivefs.GoogleDriveFileSystem(token='cache', tokens_file=creds)
assert fs.ls("")
Expand All @@ -30,3 +29,17 @@ def test_simple(creds):
with fs.open(fn, 'wb') as f:
f.write(data)
assert fs.cat(fn) == data

def test_create_directory(creds):
fs = gdrivefs.GoogleDriveFileSystem(token='cache', tokens_file=creds)
fs.makedirs(test_dir + "/data")
fs.makedirs(test_dir + "/data/bar/baz")

assert fs.exists(test_dir + "/data")
assert fs.exists(test_dir + "/data/bar")
assert fs.exists(test_dir + "/data/bar/baz")

data = b"intermediate path"
with fs.open(test_dir + "/data/bar/test", "wb") as stream:
stream.write(data)
assert fs.cat(test_dir + "/data/bar/test") == data

0 comments on commit 749cd9d

Please sign in to comment.