Rollup merge of #22727 - alexcrichton:prep-env, r=aturon

This commit moves `std::env` away from the `std::old_io` error type as well as
the `std::old_path` module. Methods returning an error now return `io::Error`
and methods consuming or returning paths use `std::path` instead of
`std::old_path`. This commit does not yet mark these APIs as `#[stable]`.

This commit also migrates `std::old_io::TempDir` to `std::fs::TempDir` with
essentially the exact same API. This type was added to interoperate with the new
path API and has its own `tempdir` feature.

Finally, this commit reverts the deprecation of `std::os` APIs returning the old
path API types. This deprecation can come back once the entire `std::old_path`
module is deprecated.

[breaking-change]
This commit is contained in:
Manish Goregaokar 2015-02-25 10:29:39 +05:30
commit b18584cbd9
31 changed files with 323 additions and 141 deletions

View file

@ -9,13 +9,14 @@
// except according to those terms.
use std::env::*;
use std::path::PathBuf;
#[cfg(unix)]
fn main() {
let oldhome = var("HOME");
set_var("HOME", "/home/MountainView");
assert!(home_dir() == Some(Path::new("/home/MountainView")));
assert!(home_dir() == Some(PathBuf::new("/home/MountainView")));
remove_var("HOME");
if cfg!(target_os = "android") {

View file

@ -1,5 +1,3 @@
// no-prefer-dynamic
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
@ -10,12 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::slice::SliceExt;
use std::old_io::{fs, USER_RWX};
use std::process;
// no-prefer-dynamic
#![feature(fs, process, env, path, rand)]
use std::env;
use std::old_path::BytesContainer;
use std::fs;
use std::process;
use std::rand::random;
use std::str;
fn main() {
// If we're the child, make sure we were invoked correctly
@ -34,21 +35,20 @@ fn main() {
fn test() {
// If we're the parent, copy our own binary to a new directory.
let my_path = env::current_exe().unwrap();
let my_dir = my_path.dir_path();
let my_dir = my_path.parent().unwrap();
let random_u32: u32 = random();
let child_dir = Path::new(my_dir.join(format!("issue-15149-child-{}",
random_u32)));
fs::mkdir(&child_dir, USER_RWX).unwrap();
let child_dir = my_dir.join(&format!("issue-15149-child-{}", random_u32));
fs::create_dir(&child_dir).unwrap();
let child_path = child_dir.join(format!("mytest{}",
env::consts::EXE_SUFFIX));
let child_path = child_dir.join(&format!("mytest{}",
env::consts::EXE_SUFFIX));
fs::copy(&my_path, &child_path).unwrap();
// Append the new directory to our own PATH.
let path = {
let mut paths: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap()).collect();
paths.push(child_dir.clone());
paths.push(child_dir.to_path_buf());
env::join_paths(paths.iter()).unwrap()
};
@ -58,9 +58,9 @@ fn test() {
assert!(child_output.status.success(),
format!("child assertion failed\n child stdout:\n {}\n child stderr:\n {}",
child_output.stdout.container_as_str().unwrap(),
child_output.stderr.container_as_str().unwrap()));
str::from_utf8(&child_output.stdout).unwrap(),
str::from_utf8(&child_output.stderr).unwrap()));
fs::rmdir_recursive(&child_dir).unwrap();
fs::remove_dir_all(&child_dir).unwrap();
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::old_io::{process, Command};
use std::process::Command;
use std::env;
fn main() {
@ -22,10 +22,8 @@ fn main() {
}
fn test() {
let status = Command::new(env::current_exe().unwrap())
let status = Command::new(&env::current_exe().unwrap())
.arg("foo").arg("")
.stdout(process::InheritFd(1))
.stderr(process::InheritFd(2))
.status().unwrap();
assert!(status.success());
}

View file

@ -8,14 +8,19 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-windows currently windows requires UTF-8 for spawning processes
use std::old_io::Command;
use std::env;
#[cfg(unix)]
fn main() {
use std::process::Command;
use std::env;
use std::os::unix::prelude::*;
use std::ffi::OsStr;
if env::args().len() == 1 {
assert!(Command::new(env::current_exe().unwrap()).arg(b"\xff")
assert!(Command::new(&env::current_exe().unwrap())
.arg(<OsStr as OsStrExt>::from_bytes(b"\xff"))
.status().unwrap().success())
}
}
#[cfg(windows)]
fn main() {}