From 057b8c64c018bf0ae2d6984283aef6606cb426dd Mon Sep 17 00:00:00 2001 From: Ryn Daniels <397565+ryndaniels@users.noreply.github.com> Date: Wed, 12 Jan 2022 10:34:23 +0100 Subject: [PATCH] Check for assets with size of 0 bytes (#10026) * Check for assets with size of 0 bytes * Update spacy/cli/project/assets.py Co-authored-by: Sofie Van Landeghem Co-authored-by: Sofie Van Landeghem --- spacy/cli/project/assets.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/spacy/cli/project/assets.py b/spacy/cli/project/assets.py index b5057e401..5e0cdfdf2 100644 --- a/spacy/cli/project/assets.py +++ b/spacy/cli/project/assets.py @@ -1,6 +1,7 @@ from typing import Any, Dict, Optional from pathlib import Path from wasabi import msg +import os import re import shutil import requests @@ -129,10 +130,17 @@ def fetch_asset( the asset failed. """ dest_path = (project_path / dest).resolve() - if dest_path.exists() and checksum: + if dest_path.exists(): # If there's already a file, check for checksum - if checksum == get_checksum(dest_path): - msg.good(f"Skipping download with matching checksum: {dest}") + if checksum: + if checksum == get_checksum(dest_path): + msg.good(f"Skipping download with matching checksum: {dest}") + return + else: + # If there's not a checksum, make sure the file is a possibly valid size + if os.path.getsize(dest_path) == 0: + msg.warn(f"Asset exists but with size of 0 bytes, deleting: {dest}") + os.remove(dest_path) # We might as well support the user here and create parent directories in # case the asset dir isn't listed as a dir to create in the project.yml if not dest_path.parent.exists():