Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
76f7433
Track Drive folders by parent ID and exact name
shcheklein Nov 28, 2026
aa8ca7f
Stop warm directory checks at the first verified match
shcheklein Nov 28, 2026
e597687
Refresh same-name folders discovered during a file rename
shcheklein Nov 28, 2026
2a80989
Return a consistent tuple of known folder IDs
shcheklein Nov 28, 2026
51faac3
Reuse known folders through file-name collisions and narrow Drive probes
shcheklein Nov 28, 2026
c595e52
Order folder cache observations across overlapping Drive requests
shcheklein Nov 28, 2026
22b92f0
Use the latest parent seen for an item across Drive listing batches
shcheklein Nov 28, 2026
7b3f614
Move items into folder IDs when destination names are ambiguous
shcheklein Nov 28, 2026
94b9d13
Reuse warm folder IDs for traversal and bound hidden-parent lookups
shcheklein Nov 28, 2026
2d57699
Bound memory used by paginated Drive directory listings
shcheklein Nov 28, 2026
741751e
Recheck moved folders by destination ID and cover review findings
shcheklein Nov 28, 2026
c89809b
Share directory resolution and keep names-only scans lightweight
shcheklein Nov 29, 2026
c1541ac
Simplify Drive lookups and release stale listing entries
shcheklein Nov 29, 2026
3cb93e7
Describe filesystem caching and credentials in PyDrive2 terms
shcheklein Nov 29, 2026
535085c
Count Drive API listings in the live cache test
shcheklein Nov 29, 2026
b7ef2ab
Keep moved folders reachable and reduce listing memory
shcheklein Nov 30, 2026
d28828b
Reuse fully listed parents and release file IDs between pages
shcheklein Nov 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions docs/fsspec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,17 @@ argument specifies traversal depth. Directory names returned by ``ls()``
and ``info()`` end in a slash. ``find(withdirs=True)`` returns directory
paths without a trailing slash, like fsspec's other traversal methods.

Named directory lookups reuse cached Drive IDs. If another client moves,
trashes, or deletes a folder, call ``fs.invalidate_cache("root/empty")``
before looking up its old path again. The next lookup checks Drive for all
folders with that name, including any same-name folder that still exists.
Named directory lookups reuse cached Drive IDs. Listing a parent refreshes
the folders seen under that parent. If a listing discovers a folder under
a new name, its cached children follow the folder's Drive ID. If another
client moves, trashes, or deletes a folder, call
``fs.invalidate_cache("root/empty")`` before looking up its old path again.
The next lookup checks Drive for all folders with that name, including any
same-name folder that still exists.

Only folder IDs are cached between calls. Both ``ls()`` and ``find()``
build their results in memory, so larger listings use more memory during
the call.

Drive queries for directory entries exclude trashed items. For a bare file
ID, ``exists()`` returns false and ``info()`` raises ``FileNotFoundError``
Expand Down Expand Up @@ -188,6 +195,9 @@ repeated lookups. After an external move or deletion, use
``fs.invalidate_cache(path)`` for the affected path or
``fs.invalidate_cache()`` to clear the whole cache.

When listing a single Drive folder, ``ls()`` returns entries in page order.
A file renamed during pagination can appear under both names.

For sequential reads, pass a positive ``block_size`` to ``fs.open()`` to set
the Drive download request size in bytes. A writer buffers data locally,
using a temporary file for larger uploads. Calling ``flush()`` flushes the
Expand Down
17 changes: 14 additions & 3 deletions docs/upgrading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,25 @@ during sign-in and provision the resulting token JSON. See :doc:`oauth`.

The fsspec backend uses a separate default cache for 2.0. Its first
interactive connection prompts for a login. If you pass an explicit user
cache path, choose a new path. For DVC remotes that use
``GDRIVE_CREDENTIALS_DATA`` for a user account, replace its value with the
newly saved credentials.
cache path, choose a new path. If you pass user credentials through
``client_json``, use the newly saved token JSON.

Service accounts use their configured JSON or PKCS12 signing key. Keep the
key available to the application. Deployments that relied solely on a
saved service-account token need to provision the signing key.

Filesystem directory lookups
----------------------------

The :doc:`fsspec filesystem <fsspec>` now caches folders returned by
``ls()``. Later calls such as ``exists("root/data")`` can reuse those IDs.
If another client moves or removes a folder, list its parent again or
call ``fs.invalidate_cache("root/data")`` before checking the old path.

Filesystem listings and path lookups read Drive metadata pages directly.
If your application intercepts requests through ``GoogleDrive.ListFile()``,
use the HTTP transport to observe those filesystem requests.

Drive API fields and requests
-----------------------------

Expand Down
30 changes: 15 additions & 15 deletions pydrive2/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
)
from .auth import LoadAuth

FOLDER_MIME_TYPE = "application/vnd.google-apps.folder"
DEFAULT_FILE_FIELDS = (
"id,name,mimeType,description,parents,trashed,size,md5Checksum,"
"resourceKey,webViewLink,createdTime,modifiedTime"
Expand Down Expand Up @@ -99,22 +100,11 @@ def _decorated(self, *args, **kwargs):
return _decorated


class GoogleDriveFileList(ApiResourceList):
"""Google Drive FileList instance.

Equivalent to Files.list() in Drive APIs.
"""

def __init__(self, auth=None, param=None):
"""Create an instance of GoogleDriveFileList."""
super().__init__(auth=auth, metadata=param)
class _FileMetadataPages(ApiResourceList):
"""Drive file metadata, one API response per iteration."""

@LoadAuth
def _GetList(self):
"""Overwritten method which actually makes API call to list files.

:returns: list -- list of pydrive2.files.GoogleDriveFile.
"""
params = dict(
self, supportsAllDrives=True, includeItemsFromAllDrives=True
)
Expand All @@ -130,9 +120,19 @@ def _GetList(self):
except errors.HttpError as error:
raise ApiRequestError(error)

return self.metadata.get("files", [])


class GoogleDriveFileList(_FileMetadataPages):
"""GoogleDriveFile objects returned by Drive's files.list API."""

def __init__(self, auth=None, param=None):
super().__init__(auth=auth, metadata=param)

def _GetList(self):
return [
GoogleDriveFile(self.auth, metadata, uploaded=True)
for metadata in self.metadata.get("files", [])
for metadata in super()._GetList()
]


Expand Down Expand Up @@ -485,7 +485,7 @@ def FetchContent(self, mimetype=None, remove_bom=False):
if not self.uploaded and not self._SourceMimeType():
self.FetchMetadata()
if self._SourceMimeType() in {
"application/vnd.google-apps.folder",
FOLDER_MIME_TYPE,
"application/vnd.google-apps.shortcut",
}:
raise FileNotDownloadableError(
Expand Down
Loading
Loading