Allow listing an empty drive root - #64
Conversation
|
What happens if the drive in question doesn't exist at all? I would expect FileNotFound rather than an empty listing. |
ed56d6f to
01ede5e
Compare
|
Good point. I updated the branch so the empty-root case and missing-root case are distinct. Current behavior after
I also rebased the branch onto the latest Verification: .venv/bin/python -m pytest tests/test_core.py -q
# 31 passed, 2 deselected in 0.06s
.venv/bin/python -m pytest -q
# 31 passed, 2 deselected in 0.06s
ruff check gdrive_fsspec/core.py tests/test_core.py
# All checks passed!
ruff format --check gdrive_fsspec/core.py tests/test_core.py
# 2 files already formatted
git diff --check origin/master...HEAD
# no output |
| @@ -316,6 +324,17 @@ def info(self, path, trashed=False): | |||
| } | |||
| return super().info(path, trashed=trashed) | |||
|
|
|||
| def _file_id_exists(self, file_id): | |||
There was a problem hiding this comment.
Basically the same as self._list_directory_by_id ?
There was a problem hiding this comment.
Not quite — _list_directory_by_id lists the children of a directory (files.list with a parents filter) and returns [] for a missing id, which is exactly the ambiguity this disambiguates. _file_id_exists does a metadata-only files.get (fields=id) to ask whether the id itself resolves. A missing custom root then raises FileNotFoundError while an empty real root still lists [].
| and not files | ||
| and self.drive is None | ||
| and file_id != "root" | ||
| and not self._file_id_exists(file_id) |
There was a problem hiding this comment.
This gets rechecked on every call. That is ... OK, the cache doesn't have a way to say "tried but not found".
There was a problem hiding this comment.
Right — agreed. The recheck only runs in the narrow case (empty listing of a custom root), and the dircache indeed has no way to record a negative, so it's the cheapest correct option.
01ede5e to
44e4160
Compare
Summary
FileNotFoundErrorfor missing non-root pathsTests
.venv/bin/python -m pytest -q.venv/bin/pre-commit run --files gdrive_fsspec/core.py tests/test_core.pyFixes #59
AI assistance was used under my direction.