Skip to content

Allow listing an empty drive root#64

Open
gaoflow wants to merge 2 commits into
fsspec:masterfrom
gaoflow:fix-59-empty-root-ls
Open

Allow listing an empty drive root#64
gaoflow wants to merge 2 commits into
fsspec:masterfrom
gaoflow:fix-59-empty-root-ls

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • treat an empty top-level Drive listing as an empty directory instead of a missing path
  • keep FileNotFoundError for missing non-root paths
  • add unit tests for both paths

Tests

  • .venv/bin/python -m pytest -q
  • .venv/bin/pre-commit run --files gdrive_fsspec/core.py tests/test_core.py

Fixes #59

AI assistance was used under my direction.

@martindurant

Copy link
Copy Markdown
Member

What happens if the drive in question doesn't exist at all? I would expect FileNotFound rather than an empty listing.

@gaoflow

gaoflow commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Good point. I updated the branch so the empty-root case and missing-root case are distinct.

Current behavior after 01ede5e:

  • ls("") on an existing but empty default/root folder still returns [].
  • ls("") with a custom root_file_id that exists but has no children still returns [].
  • ls("") with a custom root_file_id whose listing is empty and whose id cannot be resolved now raises FileNotFoundError instead of caching/returning an empty listing.

I also rebased the branch onto the latest master, which should resolve the dirty merge state.

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

@martindurant martindurant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one question

Comment thread src/gdrive_fsspec/core.py
@@ -316,6 +324,17 @@ def info(self, path, trashed=False):
}
return super().info(path, trashed=trashed)

def _file_id_exists(self, file_id):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically the same as self._list_directory_by_id ?

Comment thread src/gdrive_fsspec/core.py
and not files
and self.drive is None
and file_id != "root"
and not self._file_id_exists(file_id)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets rechecked on every call. That is ... OK, the cache doesn't have a way to say "tried but not found".

@gaoflow
gaoflow force-pushed the fix-59-empty-root-ls branch from 01ede5e to 44e4160 Compare July 15, 2026 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ls("") raises FileNotFoundError on an empty drive

2 participants