diff --git a/dvc/tree/gdrive.py b/dvc/tree/gdrive.py index 5e34fa455..abf48d17a 100644 --- a/dvc/tree/gdrive.py +++ b/dvc/tree/gdrive.py @@ -381,6 +381,9 @@ class GDriveTree(BaseTree): # it does not create a file on the remote gdrive_file = self._drive.CreateFile(param) + gdrive_file.FetchMetadata(fields="fileSize") + size = gdrive_file["fileSize"] + with Tqdm( desc=progress_desc, disable=no_progress_bar, @@ -388,7 +391,13 @@ class GDriveTree(BaseTree): # explicit `bar_format` as `total` will be set by `update_to` bar_format=Tqdm.BAR_FMT_DEFAULT, ) as pbar: - gdrive_file.GetContentFile(to_file, callback=pbar.update_to) + if size: + gdrive_file.GetContentFile(to_file, callback=pbar.update_to) + else: + # PyDrive doesn't like downloading empty files + # https://github.com/iterative/dvc/issues/4286 + with open(to_file, "w"): + pass @contextmanager @_gdrive_retry