Repository navigation
Allow listing an empty drive root #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -281,7 +281,15 @@ def ls(self, path, detail=False, trashed=False): | |
| files = self._list_directory_by_id( | ||
| file_id, trashed=trashed, path_prefix=pref | ||
| ) | ||
| if files: | ||
| if ( | ||
| path == "" | ||
| and not files | ||
| and self.drive is None | ||
| and file_id != "root" | ||
| and not self._file_id_exists(file_id) | ||
| ): | ||
| raise FileNotFoundError(path) | ||
| if files or path == "": | ||
| self.dircache[pref] = files | ||
| else: | ||
| raise FileNotFoundError(path) | ||
|
|
@@ -316,6 +324,17 @@ def info(self, path, trashed=False): | |
| } | ||
| return super().info(path, trashed=trashed) | ||
|
|
||
| def _file_id_exists(self, file_id): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically the same as self._list_directory_by_id ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not quite — |
||
| try: | ||
| self.files.get( | ||
| fileId=file_id, supportsAllDrives=True, fields="id" | ||
| ).execute() | ||
| except HttpError as e: | ||
| if e.resp.status == 404: | ||
| return False | ||
| raise | ||
| return True | ||
|
|
||
| def _drive_kw(self): | ||
| if self.drive is not None: | ||
| return dict( | ||
|
|
||
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.