Skip to content

Commit dd38912

Browse files
committed
Support remote directory listing
1 parent 8f67a94 commit dd38912

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

plugins/yjs/fps_yjs/ydocs/ydrive.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def _callback(self, events):
8383
for event in events:
8484
if isinstance(event, MapEvent):
8585
current = self._ycontent
86-
for path in event.path:
87-
current = current[path]
86+
for p in event.path:
87+
current = current[p]
8888
for key, val in event.keys.items():
8989
action = val.get("action")
9090
if action == "delete":
@@ -101,6 +101,10 @@ def _callback(self, events):
101101
self._task_group.start_soon(self._try_create_directory, path)
102102
else:
103103
self._task_group.start_soon(self._try_create_file, path)
104+
elif action == "update":
105+
if val["newValue"] == "update":
106+
path = "/".join(event.path[1::2])
107+
self._task_group.start_soon(self.ls, path)
104108

105109
@property
106110
def version(self) -> str:
@@ -152,7 +156,7 @@ async def _get_directory_content(self, path: Path) -> Map:
152156
return Map(res)
153157

154158
async def _maybe_populate_dir(self, path: Path, content: Map):
155-
if content["content"] is None:
159+
if not isinstance(content["content"], Map):
156160
content["content"] = await self._get_directory_content(path)
157161

158162
async def _get(self, path: Path | str | None = None) -> Map:

plugins/yjs/tests/test_ydocs.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ async def test_ydrive():
5757
await ydrive.ls("doesnt_exist")
5858
assert str(exc_info.value) == "404: Item not found"
5959

60+
# remote ydrive.ls()
61+
assert ydrive._ycontent["content"] is None
62+
ydrive._ycontent["content"] = "update"
63+
await assert_with_timeout(lambda: ydrive._ycontent["content"] != "update")
64+
assert "file0" in ydrive._ycontent["content"]
65+
assert "file1" in ydrive._ycontent["content"]
66+
assert "dir0" in ydrive._ycontent["content"]
67+
assert "dir1" in ydrive._ycontent["content"]
68+
ydrive._ycontent["content"]["dir0"]["content"] = "update"
69+
await assert_with_timeout(
70+
lambda: ydrive._ycontent["content"]["dir0"]["content"] != "update"
71+
)
72+
assert len(ydrive._ycontent["content"]["dir0"]["content"]) == 1
73+
assert "file2" in ydrive._ycontent["content"]["dir0"]["content"]
74+
6075
root_dir = await ydrive.ls()
6176
assert "file0" in root_dir
6277
assert "file1" in root_dir

0 commit comments

Comments
 (0)