Skip to content

Commit 7618efa

Browse files
committed
Prevent crashes when writing PDF files in case there is no write access.
1 parent 7398493 commit 7618efa

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Sources/LispKit/Graphics/Drawing.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ public final class Drawing: Reference {
121121
title: String? = nil,
122122
author: String? = nil,
123123
creator: String? = nil) -> Bool {
124+
// First check if we can write to the URL
125+
guard FileManager.default.isWritableFile(atPath: url.path) else {
126+
return false
127+
}
128+
// Define a media box
124129
var mediaBox = NSRect(x: 0, y: 0, width: Double(width), height: Double(height))
125130
// Create a core graphics context suitable for drawing the image into a PDF file
126131
var pdfInfo = NSMutableDictionary()

0 commit comments

Comments
 (0)