Skip to content

Commit 25c83ef

Browse files
committed
URL.withUnsafeFileSystemRepresentation will pass an optional so usage points need to account for that
also corrected an error with the deferred unlink when using urls in TestNSTask.swift
1 parent 8503b92 commit 25c83ef

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

TestFoundation/TestNSTask.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,12 @@ class TestNSTask : XCTestCase {
249249

250250
private func mkstemp(template: String, body: (FileHandle) throws -> Void) rethrows {
251251
let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("TestNSTask.XXXXXX")
252-
var buffer = [Int8](repeating: 0, count: Int(PATH_MAX))
252+
253253
try url.withUnsafeFileSystemRepresentation {
254-
switch mkstemp(UnsafeMutablePointer(mutating: $0)) {
254+
switch mkstemp(UnsafeMutablePointer(mutating: $0!)) {
255255
case -1: XCTFail("Could not create temporary file")
256256
case let fd:
257-
defer { unlink(&buffer) }
257+
defer { url.withUnsafeFileSystemRepresentation { _ = unlink($0!) } }
258258
try body(FileHandle(fileDescriptor: fd, closeOnDealloc: true))
259259
}
260260
}

TestFoundation/TestNSURL.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class TestNSURL : XCTestCase {
243243
let cwdURL = URL(fileURLWithPath: cwd, isDirectory: true)
244244
// 1 for path separator
245245
cwdURL.withUnsafeFileSystemRepresentation {
246-
gRelativeOffsetFromBaseCurrentWorkingDirectory = UInt(strlen($0) + 1)
246+
gRelativeOffsetFromBaseCurrentWorkingDirectory = UInt(strlen($0!) + 1)
247247
}
248248

249249

0 commit comments

Comments
 (0)