Skip to content

Commit

Permalink
Handle no space left
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsmkn committed Dec 8, 2023
1 parent 76487bf commit 65f0022
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions sagemaker_shim/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import errno
import logging
import re
import zipfile
Expand Down Expand Up @@ -65,8 +66,16 @@ def safe_extract(*, src: Path, dest: Path) -> None:
f"Extracting {member['src']=} from {src} to {file_dest}"
)

with zf.open(member["src"], "r") as fs, open(
file_dest, "wb"
) as fd:
while chunk := fs.read(8192):
fd.write(chunk)
try:
with zf.open(member["src"], "r") as fs, open(
file_dest, "wb"
) as fd:
while chunk := fs.read(8192):
fd.write(chunk)
except OSError as error:
if error.errno == errno.ENOSPC:
raise ZipExtractionError(
"Contents of zip file too large"
) from error
else:
raise error

0 comments on commit 65f0022

Please sign in to comment.