diff --git a/pydrive2/fs/spec.py b/pydrive2/fs/spec.py index ca9a1c4f..8c150fdb 100644 --- a/pydrive2/fs/spec.py +++ b/pydrive2/fs/spec.py @@ -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 @@ -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( @@ -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