diff options
author | Casper Beyer <caspervonb@pm.me> | 2020-06-10 00:29:12 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-09 18:29:12 +0200 |
commit | 1e0808d501cf9adea65e7cacd123ea4fea06a13a (patch) | |
tree | 5322e873b5d1f7be7c39f7e8f637c333c51a38e3 /cli/ops/io.rs | |
parent | 314f666897e63ab9f982726724a7e4af1ca798a8 (diff) |
fix: Deno.readSync on stdin (#6126)
Currently sync operations on stdin are failing because tokio::Stdin
cannot be converted to a std::File.
This commit replaces tokio::stdin with a raw file descriptor
wrapped in a std::fs::File which can be converted to a
tokio::File and back again making the synchronous version
of op_read actually work.
Diffstat (limited to 'cli/ops/io.rs')
-rw-r--r-- | cli/ops/io.rs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/cli/ops/io.rs b/cli/ops/io.rs index 0e007ad1a..785bb42b7 100644 --- a/cli/ops/io.rs +++ b/cli/ops/io.rs @@ -37,6 +37,17 @@ lazy_static! { /// resource table is dropped storing reference to that handle, the handle /// itself won't be closed (so Deno.core.print) will still work. // TODO(ry) It should be possible to close stdout. + static ref STDIN_HANDLE: std::fs::File = { + #[cfg(not(windows))] + let stdin = unsafe { std::fs::File::from_raw_fd(0) }; + #[cfg(windows)] + let stdin = unsafe { + std::fs::File::from_raw_handle(winapi::um::processenv::GetStdHandle( + winapi::um::winbase::STD_INPUT_HANDLE, + )) + }; + stdin + }; static ref STDOUT_HANDLE: std::fs::File = { #[cfg(not(windows))] let stdout = unsafe { std::fs::File::from_raw_fd(1) }; @@ -71,10 +82,10 @@ pub fn get_stdio() -> ( StreamResourceHolder, StreamResourceHolder, ) { - let stdin = StreamResourceHolder::new(StreamResource::Stdin( - tokio::io::stdin(), - TTYMetadata::default(), - )); + let stdin = StreamResourceHolder::new(StreamResource::FsFile(Some({ + let stdin = STDIN_HANDLE.try_clone().unwrap(); + (tokio::fs::File::from_std(stdin), FileMetadata::default()) + }))); let stdout = StreamResourceHolder::new(StreamResource::FsFile(Some({ let stdout = STDOUT_HANDLE.try_clone().unwrap(); (tokio::fs::File::from_std(stdout), FileMetadata::default()) |