Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Dec 18, 2023
1 parent 5b2f587 commit 5d381aa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ jobs:
- name: Run tests
run: |
hatch run dev.jupyterlab-noauth:pytest plugins/yjs/tests -v --color=yes
hatch run dev.jupyterlab-noauth:pytest plugins/yjs/tests -vs --color=yes
hatch run dev.jupyterlab-auth:test
9 changes: 9 additions & 0 deletions plugins/contents/fps_contents/fileid.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,23 @@ async def watch_files(self):
await db.commit()
self.initialized.set()

print(f"{self.root_dir=}")
print(f"{self.db_path=}")
async for changes in awatch(self.root_dir, stop_event=self.stop_watching_files):
print(f"{self.lock=}")
async with self.lock:
async with aiosqlite.connect(self.db_path) as db:
print("connect")
deleted_paths = set()
added_paths = set()
for change, changed_path in changes:
print(f"{change=} {changed_path=}")
# get relative path
changed_path = Path(changed_path).relative_to(
await Path(self.root_dir).absolute()
)
changed_path_str = str(changed_path)
print(f"{changed_path=} {changed_path_str=}")

if change == Change.deleted:
logger.debug("File %s was deleted", changed_path_str)
Expand All @@ -130,6 +136,7 @@ async def watch_files(self):
)
elif change == Change.added:
logger.debug("File %s was added", changed_path_str)
print("maybe_rename")
await maybe_rename(
db, changed_path_str, added_paths, deleted_paths, True
)
Expand All @@ -156,8 +163,10 @@ async def watch_files(self):
logger.debug("Unindexing file %s ", path)
await db.execute("DELETE FROM fileids WHERE path = ?", (path,))
await db.commit()
print("commit")

for change in changes:
print(f"{changes=}")
changed_path = change[1]
# get relative path
relative_changed_path = Path(changed_path).relative_to(
Expand Down
10 changes: 9 additions & 1 deletion plugins/yjs/tests/test_ydocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
@pytest.mark.anyio
async def test_ydrive():
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_dir = Path(tmp_dir)
print(f"{tmp_dir=}")
tmp_dir = Path(tmp_dir).resolve()
print(f"{tmp_dir=}")
(tmp_dir / "file0").write_text(" " * 1)
(tmp_dir / "file1").write_text(" " * 2)
(tmp_dir / "dir0").mkdir()
Expand All @@ -20,6 +22,9 @@ async def test_ydrive():
(tmp_dir / "dir1" / "dir2" / "file3").write_text(" " * 4)
(tmp_dir / "dir1" / "dir2" / "file4").write_text(" " * 5)

print(f"{list(tmp_dir.iterdir())=}")
print(f'{list(Path("/private" + str(tmp_dir)).iterdir())=}')

contents = Contents(db_path=str(tmp_dir / ".fileid.db"), root_dir=str(tmp_dir))

async with YDrive(contents=contents, root_dir=tmp_dir) as ydrive:
Expand Down Expand Up @@ -59,6 +64,9 @@ async def test_ydrive():
await contents.file_id_manager.initialized.wait()
await sleep(10)
assert "file1" in root_dir["content"]
(tmp_dir / "foo").write_text(" ")
await sleep(1)
(tmp_dir / "foo").unlink()
(tmp_dir / "file1").unlink()
for _ in range(100): # wait a total of 10s
await sleep(0.1)
Expand Down

0 comments on commit 5d381aa

Please sign in to comment.