Skip to content
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

Deleting cache for moved / removed items #237

Closed
Changes from all commits
Commits
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
15 changes: 13 additions & 2 deletions pydrive2/fs/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import posixpath
import threading
from collections import defaultdict
from contextlib import contextmanager
from contextlib import contextmanager, suppress

from fsspec.spec import AbstractFileSystem
from funcy import cached_property, retry, wrap_prop, wrap_with
Expand Down Expand Up @@ -570,9 +570,14 @@ def mv(self, path1, path2, maxdepth=None, **kwargs):
file2_parent_id = self._get_item_id(dst_parent)
file1["parents"] = [{"id": file2_parent_id}]

# TODO need to invalidate the cache for the old path, see #232
file1.Upload()

with suppress(KeyError):
del self._ids_cache["ids"][file1_id]
with suppress(KeyError):
_, base = self.split_path(path1)
del self._ids_cache["dirs"][base]

def get_file(self, lpath, rpath, callback=None, block_size=None, **kwargs):
item_id = self._get_item_id(lpath)
return self._gdrive_get_file(
Expand Down Expand Up @@ -622,6 +627,12 @@ def rm_file(self, path):
item_id = self._get_item_id(path)
self._gdrive_delete_file(item_id)

with suppress(KeyError):
del self._ids_cache["ids"][item_id]
with suppress(KeyError):
_, base = self.split_path(path)
del self._ids_cache["dirs"][base]

@_gdrive_retry
def _gdrive_delete_file(self, item_id):
from pydrive2.files import ApiRequestError
Expand Down