Skip to content

Commit

Permalink
Merge pull request #153 from datalad/gh-150
Browse files Browse the repository at this point in the history
Detect file downloads that end early
  • Loading branch information
jwodder committed Mar 28, 2023
2 parents a6618ff + c4c6e29 commit 92dc0bb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/datalad_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2545,6 +2545,13 @@ def download_file(
with urlopen(req) as r:
with open(path, "wb") as fp:
shutil.copyfileobj(r, fp)
if "content-length" in r.headers:
size = int(r.headers["Content-Length"])
fsize = os.path.getsize(path)
if fsize < size:
raise URLError(
f"only {fsize} out of {size} bytes were received"
)
return
except URLError as e:
if isinstance(e, HTTPError) and e.code not in (500, 502, 503, 504):
Expand Down

0 comments on commit 92dc0bb

Please sign in to comment.