diff --git a/dvc/tree/gdrive.py b/dvc/tree/gdrive.py index 5e34fa4551..abf48d17ab 100644 --- a/dvc/tree/gdrive.py +++ b/dvc/tree/gdrive.py @@ -381,6 +381,9 @@ def _gdrive_download_file( # 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 @@ def _gdrive_download_file( # 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 diff --git a/setup.py b/setup.py index 875ab04d1d..064cb12618 100644 --- a/setup.py +++ b/setup.py @@ -75,7 +75,7 @@ def run(self): "networkx>=2.1,<2.5", "pydot>=1.2.4", "speedcopy>=2.0.1; python_version < '3.8' and sys_platform == 'win32'", - "flatten_json>=0.1.6", + "flatten_json>=0.1.6,<0.1.8", "tabulate>=0.8.7", "pygtrie==2.3.2", "dpath>=2.0.1,<3",