Skip to content

Commit f89e867

Browse files
committed
remove os_pipe dependency
1 parent 1ea45dc commit f89e867

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

Cargo.lock

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ description = "Cross platform scripting for deno task"
1111

1212
[features]
1313
default = ["shell"]
14-
shell = ["deno_path_util", "futures", "glob", "nix", "os_pipe", "path-dedot", "tokio", "windows-sys", "sys_traits", "which"]
14+
shell = ["deno_path_util", "futures", "glob", "nix", "path-dedot", "tokio", "windows-sys", "sys_traits", "which"]
1515
serialization = ["serde"]
1616

1717
[dependencies]
1818
anyhow = "1.0.75"
1919
futures = { version = "0.3.29", optional = true }
2020
glob = { version = "0.3.1", optional = true }
2121
path-dedot = { version = "3.1.1", optional = true }
22-
os_pipe = { version = "1.1.4", optional = true }
2322
serde = { version = "1", features = ["derive"], optional = true }
2423
monch = "0.5.0"
2524
thiserror = "2.0.9"

src/shell/types.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl ExecuteResult {
251251
/// Reader side of a pipe.
252252
#[derive(Debug)]
253253
pub enum ShellPipeReader {
254-
OsPipe(os_pipe::PipeReader),
254+
OsPipe(std::io::PipeReader),
255255
StdFile(std::fs::File),
256256
}
257257

@@ -266,10 +266,32 @@ impl Clone for ShellPipeReader {
266266

267267
impl ShellPipeReader {
268268
pub fn stdin() -> ShellPipeReader {
269-
ShellPipeReader::from_raw(os_pipe::dup_stdin().unwrap())
269+
#[cfg(unix)]
270+
pub fn dup_stdin_as_pipe_reader() -> std::io::PipeReader {
271+
use std::os::fd::AsFd;
272+
use std::os::fd::IntoRawFd;
273+
use std::os::fd::FromRawFd;
274+
let owned = std::io::stdin().as_fd().try_clone_to_owned().unwrap();
275+
let raw = owned.into_raw_fd(); // transfer ownership
276+
// SAFETY: `raw` is a fresh, owned fd; PipeReader will close it.
277+
unsafe { std::io::PipeReader::from_raw_fd(raw) }
278+
}
279+
280+
#[cfg(windows)]
281+
pub fn dup_stdin_as_pipe_reader() -> io::Result<PipeReader> {
282+
use std::os::windows::io::AsHandle;
283+
use std::os::windows::io::IntoRawHandle;
284+
use std::os::windows::io::FromRawHandle;
285+
let owned = io::stdin().as_handle().try_clone_to_owned().unwrap();
286+
let raw = owned.into_raw_handle(); // transfer ownership
287+
// SAFETY: `raw` is a fresh, owned HANDLE; PipeReader will close it.
288+
unsafe { std::io::PipeReader::from_raw_handle(raw) }
289+
}
290+
291+
ShellPipeReader::OsPipe(dup_stdin_as_pipe_reader())
270292
}
271293

272-
pub fn from_raw(reader: os_pipe::PipeReader) -> Self {
294+
pub fn from_raw(reader: std::io::PipeReader) -> Self {
273295
Self::OsPipe(reader)
274296
}
275297

@@ -281,7 +303,7 @@ impl ShellPipeReader {
281303
#[allow(clippy::should_implement_trait)]
282304
pub fn from_str(data: &str) -> Self {
283305
use std::io::Write;
284-
let (read, mut write) = os_pipe::pipe().unwrap();
306+
let (read, mut write) = std::io::pipe().unwrap();
285307
write.write_all(data.as_bytes()).unwrap();
286308
Self::OsPipe(read)
287309
}
@@ -369,7 +391,7 @@ impl ShellPipeReader {
369391
/// prevent deadlocks where the reader hangs waiting for a read.
370392
#[derive(Debug)]
371393
pub enum ShellPipeWriter {
372-
OsPipe(os_pipe::PipeWriter),
394+
OsPipe(std::io::PipeWriter),
373395
StdFile(std::fs::File),
374396
// For stdout and stderr, instead of directly duplicating the raw pipes
375397
// and putting them in a ShellPipeWriter::OsPipe(...), we use Rust std's
@@ -468,7 +490,7 @@ impl ShellPipeWriter {
468490

469491
/// Used to communicate between commands.
470492
pub fn pipe() -> (ShellPipeReader, ShellPipeWriter) {
471-
let (reader, writer) = os_pipe::pipe().unwrap();
493+
let (reader, writer) = std::io::pipe().unwrap();
472494
(
473495
ShellPipeReader::OsPipe(reader),
474496
ShellPipeWriter::OsPipe(writer),

0 commit comments

Comments
 (0)