-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52d17c2
commit 6c6145c
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
diff --git a/Sources/TSCBasic/FileSystem.swift b/Sources/TSCBasic/FileSystem.swift | ||
index b33b1c6..1d26033 100644 | ||
--- a/Sources/TSCBasic/FileSystem.swift | ||
+++ b/Sources/TSCBasic/FileSystem.swift | ||
@@ -491,8 +491,7 @@ private struct LocalFileSystem: FileSystem { | ||
|
||
func readFileContents(_ path: AbsolutePath) throws -> ByteString { | ||
// Open the file. | ||
- let fp = fopen(path.pathString, "rb") | ||
- if fp == nil { | ||
+ guard let fp = fopen(path.pathString, "rb") else { | ||
throw FileSystemError(errno: errno, path) | ||
} | ||
defer { fclose(fp) } | ||
@@ -521,8 +520,7 @@ private struct LocalFileSystem: FileSystem { | ||
|
||
func writeFileContents(_ path: AbsolutePath, bytes: ByteString) throws { | ||
// Open the file. | ||
- let fp = fopen(path.pathString, "wb") | ||
- if fp == nil { | ||
+ guard let fp = fopen(path.pathString, "wb") else { | ||
throw FileSystemError(errno: errno, path) | ||
} | ||
defer { fclose(fp) } | ||
diff --git a/Sources/TSCBasic/Process.swift b/Sources/TSCBasic/Process.swift | ||
index 6c8aa11..89d3a5b 100644 | ||
--- a/Sources/TSCBasic/Process.swift | ||
+++ b/Sources/TSCBasic/Process.swift | ||
@@ -144,6 +144,9 @@ public final class Process { | ||
|
||
/// The current OS does not support the workingDirectory API. | ||
case workingDirectoryNotSupported | ||
+ | ||
+ /// The stdin could not be opened. | ||
+ case stdinUnavailable | ||
} | ||
|
||
public enum OutputRedirection { | ||
@@ -677,7 +680,10 @@ public final class Process { | ||
var stdinPipe: [Int32] = [-1, -1] | ||
try open(pipe: &stdinPipe) | ||
|
||
- let stdinStream = try LocalFileOutputByteStream(filePointer: fdopen(stdinPipe[1], "wb"), closeOnDeinit: true) | ||
+ guard let fp = fdopen(stdinPipe[1], "wb") else { | ||
+ throw Process.Error.stdinUnavailable | ||
+ } | ||
+ let stdinStream = try LocalFileOutputByteStream(filePointer: fp, closeOnDeinit: true) | ||
|
||
// Dupe the read portion of the remote to 0. | ||
posix_spawn_file_actions_adddup2(&fileActions, stdinPipe[0], 0) | ||
@@ -1258,6 +1264,8 @@ extension Process.Error: CustomStringConvertible { | ||
return "could not find executable for '\(program)'" | ||
case .workingDirectoryNotSupported: | ||
return "workingDirectory is not supported in this platform" | ||
+ case .stdinUnavailable: | ||
+ return "could not open stdin on this platform" | ||
} | ||
} | ||
} | ||
diff --git a/Sources/TSCBasic/WritableByteStream.swift b/Sources/TSCBasic/WritableByteStream.swift | ||
index aee907e..5b6e4c2 100644 | ||
--- a/Sources/TSCBasic/WritableByteStream.swift | ||
+++ b/Sources/TSCBasic/WritableByteStream.swift | ||
@@ -790,7 +790,7 @@ public final class LocalFileOutputByteStream: FileOutputByteStream { | ||
override final func writeImpl(_ bytes: ArraySlice<UInt8>) { | ||
bytes.withUnsafeBytes { bytesPtr in | ||
while true { | ||
- let n = fwrite(bytesPtr.baseAddress, 1, bytesPtr.count, filePointer) | ||
+ let n = fwrite(bytesPtr.baseAddress!, 1, bytesPtr.count, filePointer) | ||
if n < 0 { | ||
if errno == EINTR { continue } | ||
errorDetected(code: errno) | ||
diff --git a/Sources/TSCTestSupport/PseudoTerminal.swift b/Sources/TSCTestSupport/PseudoTerminal.swift | ||
index 59610b6..2797c71 100644 | ||
--- a/Sources/TSCTestSupport/PseudoTerminal.swift | ||
+++ b/Sources/TSCTestSupport/PseudoTerminal.swift | ||
@@ -24,7 +24,7 @@ public final class PseudoTerminal { | ||
if openpty(&primary, &secondary, nil, nil, nil) != 0 { | ||
return nil | ||
} | ||
- guard let outStream = try? LocalFileOutputByteStream(filePointer: fdopen(secondary, "w"), closeOnDeinit: false) else { | ||
+ guard let outStream = try? LocalFileOutputByteStream(filePointer: fdopen(secondary, "w")!, closeOnDeinit: false) else { | ||
return nil | ||
} | ||
self.outStream = outStream |