Skip to content

Commit b048f4e

Browse files
authored
Merge pull request #2578 from gmittert/POSIXIsAlwaysRight
[Windows] Fix TestProcess.swift
2 parents 94d6a4a + 2478c02 commit b048f4e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Foundation/Process.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,15 @@ open class Process: NSObject {
600600
DWORD(CREATE_UNICODE_ENVIRONMENT), UnsafeMutableRawPointer(mutating: wszEnvironment),
601601
wszCurrentDirectory,
602602
&siStartupInfo, &piProcessInfo) {
603-
throw _NSErrorWithWindowsError(GetLastError(), reading: false)
603+
let error = GetLastError()
604+
// If the current directory doesn't exist, Windows
605+
// throws an ERROR_DIRECTORY. Since POSIX gives an
606+
// ENOENT, we intercept the error to match the POSIX
607+
// behaviour
608+
if error == ERROR_DIRECTORY {
609+
throw _NSErrorWithWindowsError(DWORD(ERROR_FILE_NOT_FOUND), reading: true)
610+
}
611+
throw _NSErrorWithWindowsError(GetLastError(), reading: true)
604612
}
605613
}
606614
}

0 commit comments

Comments
 (0)