Skip to content

Commit

Permalink
Support remote directory listing
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Jan 12, 2024
1 parent 8f67a94 commit dd38912
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
10 changes: 7 additions & 3 deletions plugins/yjs/fps_yjs/ydocs/ydrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def _callback(self, events):
for event in events:
if isinstance(event, MapEvent):
current = self._ycontent
for path in event.path:
current = current[path]
for p in event.path:
current = current[p]
for key, val in event.keys.items():
action = val.get("action")
if action == "delete":
Expand All @@ -101,6 +101,10 @@ def _callback(self, events):
self._task_group.start_soon(self._try_create_directory, path)
else:
self._task_group.start_soon(self._try_create_file, path)
elif action == "update":
if val["newValue"] == "update":
path = "/".join(event.path[1::2])
self._task_group.start_soon(self.ls, path)

@property
def version(self) -> str:
Expand Down Expand Up @@ -152,7 +156,7 @@ async def _get_directory_content(self, path: Path) -> Map:
return Map(res)

async def _maybe_populate_dir(self, path: Path, content: Map):
if content["content"] is None:
if not isinstance(content["content"], Map):
content["content"] = await self._get_directory_content(path)

async def _get(self, path: Path | str | None = None) -> Map:
Expand Down
15 changes: 15 additions & 0 deletions plugins/yjs/tests/test_ydocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ async def test_ydrive():
await ydrive.ls("doesnt_exist")
assert str(exc_info.value) == "404: Item not found"

# remote ydrive.ls()
assert ydrive._ycontent["content"] is None
ydrive._ycontent["content"] = "update"
await assert_with_timeout(lambda: ydrive._ycontent["content"] != "update")
assert "file0" in ydrive._ycontent["content"]
assert "file1" in ydrive._ycontent["content"]
assert "dir0" in ydrive._ycontent["content"]
assert "dir1" in ydrive._ycontent["content"]
ydrive._ycontent["content"]["dir0"]["content"] = "update"
await assert_with_timeout(
lambda: ydrive._ycontent["content"]["dir0"]["content"] != "update"
)
assert len(ydrive._ycontent["content"]["dir0"]["content"]) == 1
assert "file2" in ydrive._ycontent["content"]["dir0"]["content"]

root_dir = await ydrive.ls()
assert "file0" in root_dir
assert "file1" in root_dir
Expand Down

0 comments on commit dd38912

Please sign in to comment.