Skip to content

Commit d2a6157

Browse files
committed
Fix access write checks (2nd attempt).
1 parent 7618efa commit d2a6157

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Sources/LispKit/Graphics/Drawing.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ public final class Drawing: Reference {
122122
author: String? = nil,
123123
creator: String? = nil) -> Bool {
124124
// First check if we can write to the URL
125-
guard FileManager.default.isWritableFile(atPath: url.path) else {
125+
var dir: ObjCBool = false
126+
let parent = url.deletingLastPathComponent().path
127+
guard FileManager.default.fileExists(atPath: parent, isDirectory: &dir) && dir.boolValue else {
128+
return false
129+
}
130+
guard FileManager.default.isWritableFile(atPath: parent) else {
126131
return false
127132
}
128133
// Define a media box

Sources/LispKit/Graphics/DrawingDocument.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ public final class DrawingDocument: Reference {
8383

8484
/// Save the collection as a PDF file to URL `url`.
8585
public func saveAsPDF(url: URL) -> Bool {
86+
// First check if we can write to the URL
87+
var dir: ObjCBool = false
88+
let parent = url.deletingLastPathComponent().path
89+
guard FileManager.default.fileExists(atPath: parent, isDirectory: &dir) && dir.boolValue else {
90+
return false
91+
}
92+
guard FileManager.default.isWritableFile(atPath: parent) else {
93+
return false
94+
}
8695
// Define PDF document information
8796
var pdfInfo: NSMutableDictionary = [
8897
kCGPDFContextAllowsPrinting: (self.allowsPrinting ? kCFBooleanTrue : kCFBooleanFalse) as Any,

0 commit comments

Comments
 (0)