mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-22 00:00:11 +02:00
process: Remove all items deprecated in 0.1
This commit is contained in:
+1
-166
@@ -124,13 +124,11 @@ extern crate tokio_core;
|
||||
extern crate tokio_io;
|
||||
extern crate mio;
|
||||
|
||||
use std::ffi::OsStr;
|
||||
use std::io::{self, Read, Write};
|
||||
use std::path::Path;
|
||||
use std::process::{self, ExitStatus, Output, Stdio};
|
||||
|
||||
use futures::{Future, Poll, IntoFuture};
|
||||
use futures::future::{Flatten, FutureResult, Either, ok};
|
||||
use futures::future::{Either, ok};
|
||||
use std::fmt;
|
||||
use tokio_core::reactor::Handle;
|
||||
use tokio_io::io::{read_to_end};
|
||||
@@ -171,25 +169,6 @@ pub trait CommandExt {
|
||||
/// event loop.
|
||||
fn spawn_async(&mut self, handle: &Handle) -> io::Result<Child>;
|
||||
|
||||
/// Executes a command as a child process, waiting for it to finish and
|
||||
/// collecting its exit status.
|
||||
///
|
||||
/// By default, stdin, stdout and stderr are inherited from the parent.
|
||||
///
|
||||
/// The `StatusAsync` future returned will resolve to the `ExitStatus`
|
||||
/// type in the standard library representing how the process exited. If
|
||||
/// any input/output handles are set to a pipe then they will be immediately
|
||||
/// closed after the child is spawned.
|
||||
///
|
||||
/// The `handle` specified must be a handle to a valid event loop, and all
|
||||
/// I/O this child does will be associated with the specified event loop.
|
||||
///
|
||||
/// If the `StatusAsync` future is dropped before the future resolves, then
|
||||
/// the child will be killed, if it was spawned.
|
||||
#[deprecated(note = "use the more flexible `spawn_async2` method instead")]
|
||||
#[allow(deprecated)]
|
||||
fn status_async(&mut self, handle: &Handle) -> StatusAsync;
|
||||
|
||||
/// Executes a command as a child process, waiting for it to finish and
|
||||
/// collecting its exit status.
|
||||
///
|
||||
@@ -258,23 +237,6 @@ impl CommandExt for process::Command {
|
||||
Ok(child)
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
fn status_async(&mut self, handle: &Handle) -> StatusAsync {
|
||||
let mut inner = self.spawn_async(handle);
|
||||
if let Ok(child) = inner.as_mut() {
|
||||
// Ensure we close any stdio handles so we can't deadlock
|
||||
// waiting on the child which may be waiting to read/write
|
||||
// to a pipe we're holding.
|
||||
child.stdin.take();
|
||||
child.stdout.take();
|
||||
child.stderr.take();
|
||||
}
|
||||
|
||||
StatusAsync {
|
||||
inner: inner.into_future().flatten(),
|
||||
}
|
||||
}
|
||||
|
||||
fn status_async2(&mut self, handle: &Handle) -> io::Result<StatusAsync2> {
|
||||
self.spawn_async(handle).map(|mut child| {
|
||||
// Ensure we close any stdio handles so we can't deadlock
|
||||
@@ -476,29 +438,6 @@ impl Future for WaitWithOutput {
|
||||
}
|
||||
}
|
||||
|
||||
/// Future returned by the `CommandExt::status_async` method.
|
||||
///
|
||||
/// This future is used to conveniently spawn a child and simply wait for its
|
||||
/// exit status. This future will resolves to the `ExitStatus` type in the
|
||||
/// standard library.
|
||||
#[must_use = "futures do nothing unless polled"]
|
||||
#[deprecated(note = "use the more flexible `SpawnAsync2` adapter instead")]
|
||||
#[allow(deprecated)]
|
||||
#[derive(Debug)]
|
||||
pub struct StatusAsync {
|
||||
inner: Flatten<FutureResult<Child, io::Error>>,
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl Future for StatusAsync {
|
||||
type Item = ExitStatus;
|
||||
type Error = io::Error;
|
||||
|
||||
fn poll(&mut self) -> Poll<ExitStatus, io::Error> {
|
||||
self.inner.poll()
|
||||
}
|
||||
}
|
||||
|
||||
/// Future returned by the `CommandExt::status_async2` method.
|
||||
///
|
||||
/// This future is used to conveniently spawn a child and simply wait for its
|
||||
@@ -611,107 +550,3 @@ impl Read for ChildStderr {
|
||||
|
||||
impl AsyncRead for ChildStderr {
|
||||
}
|
||||
|
||||
// deprecated from 0.1.0
|
||||
|
||||
#[deprecated(note = "use std::process::Command instead")]
|
||||
#[allow(deprecated, missing_docs)]
|
||||
#[allow(deprecated, missing_debug_implementations, missing_docs)]
|
||||
#[doc(hidden)]
|
||||
pub struct Command {
|
||||
inner: process::Command,
|
||||
#[allow(dead_code)]
|
||||
handle: Handle,
|
||||
}
|
||||
|
||||
#[deprecated(note = "use std::process::Command instead")]
|
||||
#[allow(deprecated, missing_debug_implementations, missing_docs)]
|
||||
#[doc(hidden)]
|
||||
pub struct Spawn {
|
||||
inner: Box<Future<Item=Child, Error=io::Error>>,
|
||||
}
|
||||
|
||||
#[deprecated(note = "use std::process::Command instead")]
|
||||
#[allow(deprecated, missing_docs)]
|
||||
#[doc(hidden)]
|
||||
impl Command {
|
||||
pub fn new<T: AsRef<OsStr>>(exe: T, handle: &Handle) -> Command {
|
||||
Command::_new(exe.as_ref(), handle)
|
||||
}
|
||||
|
||||
fn _new(exe: &OsStr, handle: &Handle) -> Command {
|
||||
Command {
|
||||
inner: process::Command::new(exe),
|
||||
handle: handle.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Command {
|
||||
self._arg(arg.as_ref())
|
||||
}
|
||||
|
||||
fn _arg(&mut self, arg: &OsStr) -> &mut Command {
|
||||
self.inner.arg(arg);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn args<S: AsRef<OsStr>>(&mut self, args: &[S]) -> &mut Command {
|
||||
for arg in args {
|
||||
self._arg(arg.as_ref());
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Command
|
||||
where K: AsRef<OsStr>, V: AsRef<OsStr>
|
||||
{
|
||||
self._env(key.as_ref(), val.as_ref())
|
||||
}
|
||||
|
||||
fn _env(&mut self, key: &OsStr, val: &OsStr) -> &mut Command {
|
||||
self.inner.env(key, val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Command {
|
||||
self._env_remove(key.as_ref())
|
||||
}
|
||||
|
||||
fn _env_remove(&mut self, key: &OsStr) -> &mut Command {
|
||||
self.inner.env_remove(key);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn env_clear(&mut self) -> &mut Command {
|
||||
self.inner.env_clear();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Command {
|
||||
self._current_dir(dir.as_ref())
|
||||
}
|
||||
|
||||
fn _current_dir(&mut self, dir: &Path) -> &mut Command {
|
||||
self.inner.current_dir(dir);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn spawn(mut self) -> Spawn {
|
||||
Spawn {
|
||||
inner: Box::new(self.inner.spawn_async(&self.handle).into_future()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[deprecated(note = "use std::process::Command instead")]
|
||||
#[allow(deprecated)]
|
||||
#[doc(hidden)]
|
||||
impl Future for Spawn {
|
||||
type Item = Child;
|
||||
type Error = io::Error;
|
||||
|
||||
fn poll(&mut self) -> Poll<Child, io::Error> {
|
||||
self.inner.poll()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -119,25 +119,6 @@ fn wait_with_output_captures() {
|
||||
assert_eq!(output.stderr.len(), 0);
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[test]
|
||||
fn status_closes_any_pipes() {
|
||||
let mut core = Core::new().unwrap();
|
||||
|
||||
// Cat will open a pipe between the parent and child.
|
||||
// If `status_async` doesn't ensure the handles are closed,
|
||||
// we would end up blocking forever (and time out).
|
||||
let child = cat().status_async(&core.handle());
|
||||
let timeout = Timeout::new(Duration::from_secs(1), &core.handle())
|
||||
.expect("timeout registration failed")
|
||||
.map(|()| panic!("time out exceeded! did we get stuck waiting on the child?"));
|
||||
|
||||
match core.run(child.select(timeout)) {
|
||||
Ok((status, _)) => assert!(status.success()),
|
||||
Err(_) => panic!("failed to run futures"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn status2_closes_any_pipes() {
|
||||
let mut core = Core::new().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user