Skip to content

Commit

Permalink
Remove temporary file when error is raised
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed May 9, 2023
1 parent 2a274a4 commit 8ab8cdc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/PIL/EpsImagePlugin.py
Expand Up @@ -134,6 +134,13 @@ def Ghostscript(tile, size, fp, scale=1, transparency=False):

if gs_windows_binary is not None:
if not gs_windows_binary:
try:
os.unlink(outfile)
if infile_temp:
os.unlink(infile_temp)
except OSError:
pass

Check warning on line 142 in src/PIL/EpsImagePlugin.py

View check run for this annotation

Codecov / codecov/patch

src/PIL/EpsImagePlugin.py#L137-L142

Added lines #L137 - L142 were not covered by tests

msg = "Unable to locate Ghostscript on paths"
raise OSError(msg)
command[0] = gs_windows_binary
Expand Down
2 changes: 2 additions & 0 deletions src/PIL/ImageGrab.py
Expand Up @@ -144,6 +144,8 @@ def grabclipboard():
err = subprocess.run(args, stdout=fh, stderr=subprocess.PIPE).stderr
os.close(fh)
if err:
os.unlink(filepath)

Check warning on line 147 in src/PIL/ImageGrab.py

View check run for this annotation

Codecov / codecov/patch

src/PIL/ImageGrab.py#L147

Added line #L147 was not covered by tests

msg = f"{args[0]} error: {err.strip().decode()}"
raise ChildProcessError(msg)
im = Image.open(filepath)
Expand Down
5 changes: 5 additions & 0 deletions src/PIL/JpegImagePlugin.py
Expand Up @@ -457,6 +457,11 @@ def load_djpeg(self):
if os.path.exists(self.filename):
subprocess.check_call(["djpeg", "-outfile", path, self.filename])
else:
try:
os.unlink(path)
except OSError:
pass

Check warning on line 463 in src/PIL/JpegImagePlugin.py

View check run for this annotation

Codecov / codecov/patch

src/PIL/JpegImagePlugin.py#L460-L463

Added lines #L460 - L463 were not covered by tests

msg = "Invalid Filename"
raise ValueError(msg)

Expand Down

0 comments on commit 8ab8cdc

Please sign in to comment.