Skip to content

Commit

Permalink
Throw .featureUnsupported when attempting to create temp files on W…
Browse files Browse the repository at this point in the history
…ASI (#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.
  • Loading branch information
kateinoigakukun authored Aug 1, 2024
1 parent 6bb5ff7 commit fb11420
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/FoundationEssentials/Data/Data+Writing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ private func cleanupTemporaryDirectory(at inPath: String?) {

/// Caller is responsible for calling `close` on the `Int32` file descriptor.
private func createTemporaryFile(at destinationPath: String, inPath: PathOrURL, prefix: String, options: Data.WritingOptions) throws -> (Int32, String) {
#if os(WASI)
// WASI does not have temp directories
throw CocoaError(.featureUnsupported)
#else
var directoryPath = destinationPath
if !directoryPath.isEmpty && directoryPath.last! != "/" {
directoryPath.append("/")
Expand Down Expand Up @@ -181,6 +185,7 @@ private func createTemporaryFile(at destinationPath: String, inPath: PathOrURL,
}
}
} while true
#endif // os(WASI)
}

/// Returns `(file descriptor, temporary file path, temporary directory path)`
Expand Down

0 comments on commit fb11420

Please sign in to comment.