From b6c83b20396e4aa7e96838437cbc6feca917280b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saugat=20Pachhai=20=28=E0=A4=B8=E0=A5=8C=E0=A4=97=E0=A4=BE?= =?UTF-8?q?=E0=A4=A4=29?= Date: Mon, 19 Jun 2023 07:39:20 +0545 Subject: [PATCH 1/2] fs: remove find --- pydrive2/fs/spec.py | 42 ------------------------------------------ 1 file changed, 42 deletions(-) diff --git a/pydrive2/fs/spec.py b/pydrive2/fs/spec.py index 997b0a5e..aed981b8 100644 --- a/pydrive2/fs/spec.py +++ b/pydrive2/fs/spec.py @@ -469,48 +469,6 @@ def ls(self, path, detail=False): else: return [content["name"] for content in contents] - def find(self, path, detail=False, **kwargs): - bucket, base = self.split_path(path) - - seen_paths = set() - dir_ids = [self._ids_cache["ids"].copy()] - contents = [] - while dir_ids: - query_ids = { - dir_id: dir_name - for dir_id, dir_name in dir_ids.pop().items() - if posixpath.commonpath([base, dir_name]) == base - if dir_id not in seen_paths - } - if not query_ids: - continue - - seen_paths |= query_ids.keys() - - new_query_ids = {} - dir_ids.append(new_query_ids) - for item in self._gdrive_list_ids(query_ids): - parent_id = item["parents"][0]["id"] - item_path = posixpath.join(query_ids[parent_id], item["title"]) - if item["mimeType"] == FOLDER_MIME_TYPE: - new_query_ids[item["id"]] = item_path - self._cache_path_id(item_path, item["id"]) - continue - size = item.get("fileSize") - contents.append( - { - "name": posixpath.join(bucket, item_path), - "type": "file", - "size": int(size) if size is not None else size, - "checksum": item.get("md5Checksum"), - } - ) - - if detail: - return {content["name"]: content for content in contents} - else: - return [content["name"] for content in contents] - def upload_fobj(self, stream, rpath, callback=None, **kwargs): parent_id = self._get_item_id(self._parent(rpath), create=True) if callback: From f976876dd3a5673ddc8ca4fda8100a71b228ffa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saugat=20Pachhai=20=28=E0=A4=B8=E0=A5=8C=E0=A4=97=E0=A4=BE?= =?UTF-8?q?=E0=A4=A4=29?= Date: Tue, 20 Jun 2023 16:19:31 +0545 Subject: [PATCH 2/2] cache path->id --- pydrive2/fs/spec.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pydrive2/fs/spec.py b/pydrive2/fs/spec.py index aed981b8..d69ba83d 100644 --- a/pydrive2/fs/spec.py +++ b/pydrive2/fs/spec.py @@ -441,12 +441,14 @@ def ls(self, path, detail=False): root_path = posixpath.join(bucket, base) contents = [] for item in self._gdrive_list_ids(dir_ids): - item_path = posixpath.join(root_path, item["title"]) + item_path = posixpath.join(base, item["title"]) + full_path = posixpath.join(root_path, item["title"]) if item["mimeType"] == FOLDER_MIME_TYPE: + self._cache_path_id(item_path, item["id"]) contents.append( { "type": "directory", - "name": item_path.rstrip("/") + "/", + "name": full_path.rstrip("/") + "/", "size": 0, } ) @@ -455,7 +457,7 @@ def ls(self, path, detail=False): contents.append( { "type": "file", - "name": item_path, + "name": full_path, "size": int(size) if size is not None else size, "checksum": item.get("md5Checksum"), }