Skip to content

Commit 057b8c6

Browse files
ryndanielssvlandeg
andauthored
Check for assets with size of 0 bytes (explosion#10026)
* Check for assets with size of 0 bytes * Update spacy/cli/project/assets.py Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com> Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
1 parent 5ba4171 commit 057b8c6

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

spacy/cli/project/assets.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any, Dict, Optional
22
from pathlib import Path
33
from wasabi import msg
4+
import os
45
import re
56
import shutil
67
import requests
@@ -129,10 +130,17 @@ def fetch_asset(
129130
the asset failed.
130131
"""
131132
dest_path = (project_path / dest).resolve()
132-
if dest_path.exists() and checksum:
133+
if dest_path.exists():
133134
# If there's already a file, check for checksum
134-
if checksum == get_checksum(dest_path):
135-
msg.good(f"Skipping download with matching checksum: {dest}")
135+
if checksum:
136+
if checksum == get_checksum(dest_path):
137+
msg.good(f"Skipping download with matching checksum: {dest}")
138+
return
139+
else:
140+
# If there's not a checksum, make sure the file is a possibly valid size
141+
if os.path.getsize(dest_path) == 0:
142+
msg.warn(f"Asset exists but with size of 0 bytes, deleting: {dest}")
143+
os.remove(dest_path)
136144
# We might as well support the user here and create parent directories in
137145
# case the asset dir isn't listed as a dir to create in the project.yml
138146
if not dest_path.parent.exists():

0 commit comments

Comments
 (0)