From 25f0e0765c1a644c901dbe95734245a5b78e1aee Mon Sep 17 00:00:00 2001 From: Saugat Pachhai Date: Sun, 1 Dec 2019 08:25:50 +0545 Subject: [PATCH] gs: use Blob.exists() instead of _list_paths to check for blob --- dvc/remote/gs.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/dvc/remote/gs.py b/dvc/remote/gs.py index 2fd8b492a..d732f6045 100644 --- a/dvc/remote/gs.py +++ b/dvc/remote/gs.py @@ -164,16 +164,13 @@ class RemoteGS(RemoteBASE): return bool(list(self._list_paths(dir_path, max_items=1))) def exists(self, path_info): - dir_path = path_info / "" - - if self.isdir(dir_path): + blob = self.gs.bucket(path_info.bucket).blob(path_info.path) + if blob.exists(): return True - for fname in self._list_paths(path_info): - if path_info.path == fname: - return True - - return False + # if the blob does not exist, it could be a part of a directory path + # eg: if `data/file.txt` exists, check for `data` should return True + return self.isdir(path_info / "") def _upload(self, from_file, to_info, name=None, no_progress_bar=True): bucket = self.gs.bucket(to_info.bucket)