Skip to content

Commit fb11420

Browse files
Throw .featureUnsupported when attempting to create temp files on WASI (#779)
WASI does not have temp directory concept, and does not provide mktemp family of functions, so attempting to create a temporary file should be considered a feature unsupported.
1 parent 6bb5ff7 commit fb11420

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Sources/FoundationEssentials/Data/Data+Writing.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ private func cleanupTemporaryDirectory(at inPath: String?) {
127127

128128
/// Caller is responsible for calling `close` on the `Int32` file descriptor.
129129
private func createTemporaryFile(at destinationPath: String, inPath: PathOrURL, prefix: String, options: Data.WritingOptions) throws -> (Int32, String) {
130+
#if os(WASI)
131+
// WASI does not have temp directories
132+
throw CocoaError(.featureUnsupported)
133+
#else
130134
var directoryPath = destinationPath
131135
if !directoryPath.isEmpty && directoryPath.last! != "/" {
132136
directoryPath.append("/")
@@ -181,6 +185,7 @@ private func createTemporaryFile(at destinationPath: String, inPath: PathOrURL,
181185
}
182186
}
183187
} while true
188+
#endif // os(WASI)
184189
}
185190

186191
/// Returns `(file descriptor, temporary file path, temporary directory path)`

0 commit comments

Comments
 (0)