From d7b6502784cad759cee9961426313017f052d5ba Mon Sep 17 00:00:00 2001
From: Alex Crichton
Date: Fri, 25 Oct 2013 16:48:26 -0700
Subject: [PATCH 1/5] Move rt::io traits into the prelude
These traits belong here, and were simply waiting for the std::io traits to get
removed. It's time they take their rightful positions!
---
src/libstd/prelude.rs | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs
index a15ef879e322d..0190b02fbc08f 100644
--- a/src/libstd/prelude.rs
+++ b/src/libstd/prelude.rs
@@ -67,6 +67,7 @@ pub use num::{Orderable, Signed, Unsigned, Round};
pub use num::{Primitive, Int, Float, ToStrRadix, ToPrimitive, FromPrimitive};
pub use path::{GenericPath, Path, PosixPath, WindowsPath};
pub use ptr::RawPtr;
+pub use rt::io::{Writer, Reader, Seek};
pub use send_str::{SendStr, SendStrOwned, SendStrStatic, IntoSendStr};
pub use str::{Str, StrVector, StrSlice, OwnedStr};
pub use to_bytes::IterBytes;
From 7bf58c2baaac3f7cb3c8e8d735b27ac9e7d3cd78 Mon Sep 17 00:00:00 2001
From: Alex Crichton
Date: Fri, 25 Oct 2013 16:50:08 -0700
Subject: [PATCH 2/5] Modify IoFactory's fs_mkdir, and add fs_rename
The invocation for making a directory should be able to specify a mode to make
the directory with (instead of defaulting to one particular mode). Additionally,
libuv and various OSes implement efficient versions of renaming files, so this
operation is exposed as an IoFactory call.
---
src/librustuv/file.rs | 15 +++++++++++++++
src/librustuv/uvio.rs | 14 +++++++++++---
src/librustuv/uvll.rs | 8 ++++++++
src/libstd/rt/rtio.rs | 3 ++-
src/rt/rust_uv.cpp | 5 +++++
5 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/src/librustuv/file.rs b/src/librustuv/file.rs
index 575226f79028b..2303721986c42 100644
--- a/src/librustuv/file.rs
+++ b/src/librustuv/file.rs
@@ -206,6 +206,21 @@ impl FsRequest {
assert_eq!(ret, 0);
}
+ pub fn rename(self, loop_: &Loop, path: &CString, to: &CString, cb: FsCallback) {
+ let complete_cb_ptr = {
+ let mut me = self;
+ me.req_boilerplate(Some(cb))
+ };
+ let ret = unsafe {
+ uvll::fs_rename(loop_.native_handle(),
+ self.native_handle(),
+ path.with_ref(|p| p),
+ to.with_ref(|p| p),
+ complete_cb_ptr)
+ };
+ assert_eq!(ret, 0);
+ }
+
pub fn readdir(self, loop_: &Loop, path: &CString,
flags: c_int, cb: FsCallback) {
let complete_cb_ptr = {
diff --git a/src/librustuv/uvio.rs b/src/librustuv/uvio.rs
index c34d20ed4f50f..7ecb51bb0d6ef 100644
--- a/src/librustuv/uvio.rs
+++ b/src/librustuv/uvio.rs
@@ -699,10 +699,9 @@ impl IoFactory for UvIoFactory {
assert!(!result_cell.is_empty());
return result_cell.take();
}
- fn fs_mkdir(&mut self, path: &CString) -> Result<(), IoError> {
- let mode = S_IRWXU as int;
+ fn fs_mkdir(&mut self, path: &CString, mode: int) -> Result<(), IoError> {
do uv_fs_helper(self.uv_loop(), path) |mkdir_req, l, p, cb| {
- do mkdir_req.mkdir(l, p, mode as int) |req, err| {
+ do mkdir_req.mkdir(l, p, mode) |req, err| {
cb(req, err)
};
}
@@ -714,6 +713,15 @@ impl IoFactory for UvIoFactory {
};
}
}
+ fn fs_rename(&mut self, path: &CString, to: &CString) -> Result<(), IoError> {
+ let to = to.with_ref(|p| p);
+ do uv_fs_helper(self.uv_loop(), path) |rename_req, l, p, cb| {
+ let to = unsafe { CString::new(to, false) };
+ do rename_req.rename(l, p, &to) |req, err| {
+ cb(req, err)
+ };
+ }
+ }
fn fs_readdir(&mut self, path: &CString, flags: c_int) ->
Result<~[Path], IoError> {
use str::StrSlice;
diff --git a/src/librustuv/uvll.rs b/src/librustuv/uvll.rs
index 9e86ab11286e4..9f26f9506a084 100644
--- a/src/librustuv/uvll.rs
+++ b/src/librustuv/uvll.rs
@@ -807,6 +807,12 @@ pub unsafe fn fs_rmdir(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char,
rust_uv_fs_rmdir(loop_ptr, req, path, cb)
}
+pub unsafe fn fs_rename(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char,
+ to: *c_char, cb: *u8) -> c_int {
+ #[fixed_stack_segment]; #[inline(never)];
+
+ rust_uv_fs_rename(loop_ptr, req, path, to, cb)
+}
pub unsafe fn fs_readdir(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char,
flags: c_int, cb: *u8) -> c_int {
#[fixed_stack_segment]; #[inline(never)];
@@ -1107,6 +1113,8 @@ extern {
mode: c_int, cb: *u8) -> c_int;
fn rust_uv_fs_rmdir(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char,
cb: *u8) -> c_int;
+ fn rust_uv_fs_rename(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char,
+ to: *c_char, cb: *u8) -> c_int;
fn rust_uv_fs_readdir(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char,
flags: c_int, cb: *u8) -> c_int;
fn rust_uv_fs_req_cleanup(req: *uv_fs_t);
diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs
index 82ff8071896fe..44d9f59c41062 100644
--- a/src/libstd/rt/rtio.rs
+++ b/src/libstd/rt/rtio.rs
@@ -102,8 +102,9 @@ pub trait IoFactory {
-> Result<~RtioFileStream, IoError>;
fn fs_unlink(&mut self, path: &CString) -> Result<(), IoError>;
fn fs_stat(&mut self, path: &CString) -> Result;
- fn fs_mkdir(&mut self, path: &CString) -> Result<(), IoError>;
+ fn fs_mkdir(&mut self, path: &CString, mode: int) -> Result<(), IoError>;
fn fs_rmdir(&mut self, path: &CString) -> Result<(), IoError>;
+ fn fs_rename(&mut self, path: &CString, to: &CString) -> Result<(), IoError>;
fn fs_readdir(&mut self, path: &CString, flags: c_int) ->
Result<~[Path], IoError>;
fn spawn(&mut self, config: ProcessConfig)
diff --git a/src/rt/rust_uv.cpp b/src/rt/rust_uv.cpp
index c59dacab88990..70602100f2e0d 100644
--- a/src/rt/rust_uv.cpp
+++ b/src/rt/rust_uv.cpp
@@ -592,6 +592,11 @@ extern "C" int
rust_uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, uv_fs_cb cb) {
return uv_fs_readdir(loop, req, path, flags, cb);
}
+extern "C" int
+rust_uv_fs_rename(uv_loop_t *loop, uv_fs_t* req, const char *path,
+ const char *to, uv_fs_cb cb) {
+ return uv_fs_rename(loop, req, path, to, cb);
+}
extern "C" int
rust_uv_spawn(uv_loop_t *loop, uv_process_t *p, uv_process_options_t options) {
From 9c1851019f1ef9511fa8731b8f1acb0796d1e97f Mon Sep 17 00:00:00 2001
From: Alex Crichton
Date: Fri, 25 Oct 2013 17:04:37 -0700
Subject: [PATCH 3/5] Remove all blocking std::os blocking functions
This commit moves all thread-blocking I/O functions from the std::os module.
Their replacements can be found in either std::rt::io::file or in a hidden
"old_os" module inside of native::file. I didn't want to outright delete these
functions because they have a lot of special casing learned over time for each
OS/platform, and I imagine that these will someday get integrated into a
blocking implementation of IoFactory. For now, they're moved to a private module
to prevent bitrot and still have tests to ensure that they work.
I've also expanded the extensions to a few more methods defined on Path, most of
which were previously defined in std::os but now have non-thread-blocking
implementations as part of using the current IoFactory.
The api of io::file is in flux, but I plan on changing it in the next commit as
well.
Closes #10057
---
mk/tests.mk | 6 +-
src/compiletest/compiletest.rs | 3 +-
src/compiletest/errors.rs | 8 +-
src/compiletest/header.rs | 5 +-
src/compiletest/runtest.rs | 20 +-
src/libextra/glob.rs | 13 +-
src/libextra/tempfile.rs | 11 +-
src/libextra/terminfo/searcher.rs | 10 +-
src/libextra/test.rs | 16 +-
src/libextra/uuid.rs | 1 -
src/libextra/workcache.rs | 36 +-
src/librustc/back/link.rs | 17 +-
src/librustc/driver/driver.rs | 3 +-
src/librustc/metadata/filesearch.rs | 36 +-
src/librustdoc/html/render.rs | 67 +-
src/librustdoc/lib.rs | 7 +-
src/librustpkg/api.rs | 6 +-
src/librustpkg/context.rs | 3 +-
src/librustpkg/installed_packages.rs | 8 +-
src/librustpkg/lib.rs | 31 +-
src/librustpkg/package_id.rs | 1 -
src/librustpkg/package_source.rs | 17 +-
src/librustpkg/path_util.rs | 52 +-
src/librustpkg/source_control.rs | 15 +-
src/librustpkg/tests.rs | 231 +++--
.../testsuite/pass/src/c-dependencies/pkg.rs | 2 +-
.../testsuite/pass/src/fancy-lib/pkg.rs | 8 +-
src/librustpkg/util.rs | 27 +-
src/librustpkg/version.rs | 4 +-
src/librustpkg/workcache_support.rs | 26 +-
src/librustpkg/workspace.rs | 2 +-
src/librustuv/file.rs | 20 +-
src/librustuv/uvio.rs | 17 +-
src/librustuv/uvll.rs | 12 +-
src/libstd/bool.rs | 7 +-
src/libstd/os.rs | 549 +-----------
src/libstd/path/posix.rs | 69 --
src/libstd/rand/os.rs | 8 +-
src/libstd/rt/io/file.rs | 793 +++++++++---------
src/libstd/rt/io/mod.rs | 21 +-
src/libstd/rt/io/native/file.rs | 483 +++++++++++
src/libstd/rt/io/net/unix.rs | 3 +-
src/libstd/rt/io/signal.rs | 7 +-
src/libstd/rt/io/timer.rs | 1 +
src/libstd/rt/rtio.rs | 7 +-
src/libstd/run.rs | 8 +-
src/libsyntax/ext/source_util.rs | 25 +-
src/libsyntax/parse/mod.rs | 16 +-
src/rt/rust_uv.cpp | 4 +
src/test/bench/core-std.rs | 5 +-
src/test/bench/shootout-fasta.rs | 4 +-
src/test/run-pass-fulldeps/qquote.rs | 1 +
src/test/run-pass-fulldeps/quote-tokens.rs | 12 +-
src/test/run-pass/glob-std.rs | 5 +-
src/test/run-pass/rename-directory.rs | 12 +-
src/test/run-pass/stat.rs | 9 +-
src/test/run-pass/tempfile.rs | 65 +-
57 files changed, 1363 insertions(+), 1492 deletions(-)
diff --git a/mk/tests.mk b/mk/tests.mk
index eabb5f535e61d..a24791d76af97 100644
--- a/mk/tests.mk
+++ b/mk/tests.mk
@@ -517,8 +517,8 @@ CTEST_BUILD_BASE_rpass = run-pass
CTEST_MODE_rpass = run-pass
CTEST_RUNTOOL_rpass = $(CTEST_RUNTOOL)
-CTEST_SRC_BASE_rpass-full = run-pass-full
-CTEST_BUILD_BASE_rpass-full = run-pass-full
+CTEST_SRC_BASE_rpass-full = run-pass-fulldeps
+CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps
CTEST_MODE_rpass-full = run-pass
CTEST_RUNTOOL_rpass-full = $(CTEST_RUNTOOL)
@@ -673,7 +673,7 @@ PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS)
PRETTY_DIRNAME_pretty-rpass = run-pass
-PRETTY_DIRNAME_pretty-rpass-full = run-pass-full
+PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps
PRETTY_DIRNAME_pretty-rfail = run-fail
PRETTY_DIRNAME_pretty-bench = bench
PRETTY_DIRNAME_pretty-pretty = pretty
diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs
index 7f5a72e8a2c8c..a354bc84e52b5 100644
--- a/src/compiletest/compiletest.rs
+++ b/src/compiletest/compiletest.rs
@@ -17,6 +17,7 @@ extern mod extra;
use std::os;
use std::rt;
+use std::rt::io::file;
use extra::getopts;
use extra::getopts::groups::{optopt, optflag, reqopt};
@@ -247,7 +248,7 @@ pub fn make_tests(config: &config) -> ~[test::TestDescAndFn] {
debug!("making tests from {}",
config.src_base.display());
let mut tests = ~[];
- let dirs = os::list_dir_path(&config.src_base);
+ let dirs = file::readdir(&config.src_base);
for file in dirs.iter() {
let file = file.clone();
debug!("inspecting file {}", file.display());
diff --git a/src/compiletest/errors.rs b/src/compiletest/errors.rs
index 0c94ec8ab8a83..dfadea37cd0d3 100644
--- a/src/compiletest/errors.rs
+++ b/src/compiletest/errors.rs
@@ -8,16 +8,16 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::rt::io::buffered::BufferedReader;
+use std::rt::io::file;
+
pub struct ExpectedError { line: uint, kind: ~str, msg: ~str }
// Load any test directives embedded in the file
pub fn load_errors(testfile: &Path) -> ~[ExpectedError] {
- use std::rt::io::Open;
- use std::rt::io::file::FileInfo;
- use std::rt::io::buffered::BufferedReader;
let mut error_patterns = ~[];
- let mut rdr = BufferedReader::new(testfile.open_reader(Open).unwrap());
+ let mut rdr = BufferedReader::new(file::open(testfile).unwrap());
let mut line_num = 1u;
loop {
let ln = match rdr.read_line() {
diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs
index 368c96ffe8542..68e8fd7673542 100644
--- a/src/compiletest/header.rs
+++ b/src/compiletest/header.rs
@@ -103,11 +103,10 @@ pub fn is_test_ignored(config: &config, testfile: &Path) -> bool {
}
fn iter_header(testfile: &Path, it: &fn(&str) -> bool) -> bool {
- use std::rt::io::Open;
- use std::rt::io::file::FileInfo;
use std::rt::io::buffered::BufferedReader;
+ use std::rt::io::file;
- let mut rdr = BufferedReader::new(testfile.open_reader(Open).unwrap());
+ let mut rdr = BufferedReader::new(file::open(testfile).unwrap());
loop {
let ln = match rdr.read_line() {
Some(ln) => ln, None => break
diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs
index 13c4c7948b803..7fc13467217fb 100644
--- a/src/compiletest/runtest.rs
+++ b/src/compiletest/runtest.rs
@@ -22,9 +22,7 @@ use util::logv;
use std::cell::Cell;
use std::rt::io;
-use std::rt::io::Writer;
-use std::rt::io::Reader;
-use std::rt::io::file::FileInfo;
+use std::rt::io::file;
use std::os;
use std::str;
use std::task::{spawn_sched, SingleThreaded};
@@ -173,7 +171,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
let rounds =
match props.pp_exact { Some(_) => 1, None => 2 };
- let src = testfile.open_reader(io::Open).read_to_end();
+ let src = file::open(testfile).read_to_end();
let src = str::from_utf8_owned(src);
let mut srcs = ~[src];
@@ -195,7 +193,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
let mut expected = match props.pp_exact {
Some(ref file) => {
let filepath = testfile.dir_path().join(file);
- let s = filepath.open_reader(io::Open).read_to_end();
+ let s = file::open(&filepath).read_to_end();
str::from_utf8_owned(s)
}
None => { srcs[srcs.len() - 2u].clone() }
@@ -651,10 +649,8 @@ fn compose_and_run_compiler(
}
fn ensure_dir(path: &Path) {
- if os::path_is_dir(path) { return; }
- if !os::make_dir(path, 0x1c0i32) {
- fail!("can't make dir {}", path.display());
- }
+ if path.is_dir() { return; }
+ file::mkdir(path, io::UserRWX);
}
fn compose_and_run(config: &config, testfile: &Path,
@@ -768,7 +764,7 @@ fn dump_output(config: &config, testfile: &Path, out: &str, err: &str) {
fn dump_output_file(config: &config, testfile: &Path,
out: &str, extension: &str) {
let outfile = make_out_name(config, testfile, extension);
- outfile.open_writer(io::CreateOrTruncate).write(out.as_bytes());
+ file::create(&outfile).write(out.as_bytes());
}
fn make_out_name(config: &config, testfile: &Path, extension: &str) -> Path {
@@ -924,7 +920,7 @@ fn _dummy_exec_compiled_test(config: &config, props: &TestProps,
fn _arm_push_aux_shared_library(config: &config, testfile: &Path) {
let tdir = aux_output_dir_name(config, testfile);
- let dirs = os::list_dir_path(&tdir);
+ let dirs = file::readdir(&tdir);
for file in dirs.iter() {
if file.extension_str() == Some("so") {
// FIXME (#9639): This needs to handle non-utf8 paths
@@ -1019,7 +1015,7 @@ fn disassemble_extract(config: &config, _props: &TestProps,
fn count_extracted_lines(p: &Path) -> uint {
- let x = p.with_extension("ll").open_reader(io::Open).read_to_end();
+ let x = file::open(&p.with_extension("ll")).read_to_end();
let x = str::from_utf8_owned(x);
x.line_iter().len()
}
diff --git a/src/libextra/glob.rs b/src/libextra/glob.rs
index 5297b48b0e156..a7742f771da3c 100644
--- a/src/libextra/glob.rs
+++ b/src/libextra/glob.rs
@@ -24,6 +24,8 @@
*/
use std::{os, path};
+use std::rt::io;
+use std::rt::io::file;
use std::path::is_sep;
use sort;
@@ -146,9 +148,14 @@ impl Iterator for GlobIterator {
}
fn list_dir_sorted(path: &Path) -> ~[Path] {
- let mut children = os::list_dir_path(path);
- sort::quick_sort(children, |p1, p2| p2.filename().unwrap() <= p1.filename().unwrap());
- children
+ match io::result(|| file::readdir(path)) {
+ Ok(children) => {
+ let mut children = children;
+ sort::quick_sort(children, |p1, p2| p2.filename() <= p1.filename());
+ children
+ }
+ Err(*) => ~[]
+ }
}
/**
diff --git a/src/libextra/tempfile.rs b/src/libextra/tempfile.rs
index d8fa130916a46..4affe7c1cde8a 100644
--- a/src/libextra/tempfile.rs
+++ b/src/libextra/tempfile.rs
@@ -14,6 +14,8 @@
use std::os;
use std::rand::Rng;
use std::rand;
+use std::rt::io;
+use std::rt::io::file;
/// A wrapper for a path to temporary directory implementing automatic
/// scope-pased deletion.
@@ -36,8 +38,9 @@ impl TempDir {
let mut r = rand::rng();
for _ in range(0u, 1000) {
let p = tmpdir.join(r.gen_ascii_str(16) + suffix);
- if os::make_dir(&p, 0x1c0) { // 700
- return Some(TempDir { path: Some(p) });
+ match io::result(|| file::mkdir(&p, io::UserRWX)) {
+ Err(*) => {}
+ Ok(()) => return Some(TempDir { path: Some(p) })
}
}
None
@@ -69,7 +72,9 @@ impl TempDir {
impl Drop for TempDir {
fn drop(&mut self) {
for path in self.path.iter() {
- os::remove_dir_recursive(path);
+ if path.exists() {
+ file::rmdir_recursive(path);
+ }
}
}
}
diff --git a/src/libextra/terminfo/searcher.rs b/src/libextra/terminfo/searcher.rs
index 8dff53f14a159..c5509f8aec7d7 100644
--- a/src/libextra/terminfo/searcher.rs
+++ b/src/libextra/terminfo/searcher.rs
@@ -14,7 +14,7 @@
use std::{os, str};
use std::os::getenv;
use std::rt::io;
-use std::rt::io::file::FileInfo;
+use std::rt::io::file;
/// Return path to database entry for `term`
pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
@@ -56,16 +56,16 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
// Look for the terminal in all of the search directories
for p in dirs_to_search.iter() {
- if os::path_exists(p) {
+ if p.exists() {
let f = str::from_char(first_char);
let newp = p.join_many([f.as_slice(), term]);
- if os::path_exists(&newp) {
+ if newp.exists() {
return Some(~newp);
}
// on some installations the dir is named after the hex of the char (e.g. OS X)
let f = format!("{:x}", first_char as uint);
let newp = p.join_many([f.as_slice(), term]);
- if os::path_exists(&newp) {
+ if newp.exists() {
return Some(~newp);
}
}
@@ -76,7 +76,7 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
/// Return open file for `term`
pub fn open(term: &str) -> Result<@mut io::Reader, ~str> {
match get_dbpath_for_term(term) {
- Some(x) => Ok(@mut x.open_reader(io::Open).unwrap() as @mut io::Reader),
+ Some(x) => Ok(@mut file::open(x) as @mut io::Reader),
None => Err(format!("could not find terminfo entry for {}", term))
}
}
diff --git a/src/libextra/test.rs b/src/libextra/test.rs
index f262e6c60fb35..497d4206fe327 100644
--- a/src/libextra/test.rs
+++ b/src/libextra/test.rs
@@ -31,7 +31,7 @@ use treemap::TreeMap;
use std::clone::Clone;
use std::comm::{stream, SharedChan, GenericPort, GenericChan};
use std::rt::io;
-use std::rt::io::file::FileInfo;
+use std::rt::io::file;
use std::task;
use std::to_str::ToStr;
use std::f64;
@@ -353,10 +353,7 @@ struct ConsoleTestState {
impl ConsoleTestState {
pub fn new(opts: &TestOpts) -> ConsoleTestState {
let log_out = match opts.logfile {
- Some(ref path) => {
- let out = path.open_writer(io::CreateOrTruncate);
- Some(@mut out as @mut io::Writer)
- },
+ Some(ref path) => Some(@mut file::create(path) as @mut io::Writer),
None => None
};
let out = @mut io::stdio::stdout() as @mut io::Writer;
@@ -938,16 +935,15 @@ impl MetricMap {
/// Load MetricDiff from a file.
pub fn load(p: &Path) -> MetricMap {
- assert!(os::path_exists(p));
- let f = @mut p.open_reader(io::Open) as @mut io::Reader;
+ assert!(p.exists());
+ let f = @mut file::open(p) as @mut io::Reader;
let mut decoder = json::Decoder(json::from_reader(f).unwrap());
MetricMap(Decodable::decode(&mut decoder))
}
/// Write MetricDiff to a file.
pub fn save(&self, p: &Path) {
- let f = @mut p.open_writer(io::CreateOrTruncate);
- self.to_json().to_pretty_writer(f as @mut io::Writer);
+ self.to_json().to_pretty_writer(@mut file::create(p) as @mut io::Writer);
}
/// Compare against another MetricMap. Optionally compare all
@@ -1032,7 +1028,7 @@ impl MetricMap {
/// `MetricChange`s are `Regression`. Returns the diff as well
/// as a boolean indicating whether the ratchet succeeded.
pub fn ratchet(&self, p: &Path, pct: Option) -> (MetricDiff, bool) {
- let old = if os::path_exists(p) {
+ let old = if p.exists() {
MetricMap::load(p)
} else {
MetricMap::new()
diff --git a/src/libextra/uuid.rs b/src/libextra/uuid.rs
index b94b74a696cc2..54ce349a0b484 100644
--- a/src/libextra/uuid.rs
+++ b/src/libextra/uuid.rs
@@ -792,7 +792,6 @@ mod test {
#[test]
fn test_serialize_round_trip() {
- use std;
use ebml;
use serialize::{Encodable, Decodable};
diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs
index 507962c0b1a2a..b2be4cf811b32 100644
--- a/src/libextra/workcache.rs
+++ b/src/libextra/workcache.rs
@@ -17,13 +17,11 @@ use arc::{Arc,RWArc};
use treemap::TreeMap;
use std::cell::Cell;
use std::comm::{PortOne, oneshot};
-use std::{os, str, task};
+use std::{str, task};
use std::rt::io;
-use std::rt::io::Writer;
-use std::rt::io::Reader;
+use std::rt::io::file;
use std::rt::io::Decorator;
use std::rt::io::mem::MemWriter;
-use std::rt::io::file::FileInfo;
/**
*
@@ -145,7 +143,7 @@ impl Database {
db_cache: TreeMap::new(),
db_dirty: false
};
- if os::path_exists(&rslt.db_filename) {
+ if rslt.db_filename.exists() {
rslt.load();
}
rslt
@@ -178,19 +176,19 @@ impl Database {
// FIXME #4330: This should have &mut self and should set self.db_dirty to false.
fn save(&self) {
- let f = @mut self.db_filename.open_writer(io::CreateOrTruncate);
+ let f = @mut file::create(&self.db_filename);
self.db_cache.to_json().to_pretty_writer(f as @mut io::Writer);
}
fn load(&mut self) {
assert!(!self.db_dirty);
- assert!(os::path_exists(&self.db_filename));
- let f = self.db_filename.open_reader(io::Open);
- match f {
- None => fail!("Couldn't load workcache database {}",
- self.db_filename.display()),
- Some(r) =>
- match json::from_reader(@mut r as @mut io::Reader) {
+ assert!(self.db_filename.exists());
+ match io::result(|| file::open(&self.db_filename)) {
+ Err(e) => fail!("Couldn't load workcache database {}: {}",
+ self.db_filename.display(),
+ e.desc),
+ Ok(r) =>
+ match json::from_reader(@mut r.unwrap() as @mut io::Reader) {
Err(e) => fail!("Couldn't parse workcache database (from file {}): {}",
self.db_filename.display(), e.to_str()),
Ok(r) => {
@@ -482,23 +480,21 @@ impl<'self, T:Send +
#[test]
fn test() {
use std::{os, run};
- use std::rt::io::Reader;
+ use std::rt::io::file;
use std::str::from_utf8_owned;
// Create a path to a new file 'filename' in the directory in which
// this test is running.
fn make_path(filename: ~str) -> Path {
let pth = os::self_exe_path().expect("workcache::test failed").with_filename(filename);
- if os::path_exists(&pth) {
- os::remove_file(&pth);
+ if pth.exists() {
+ file::unlink(&pth);
}
return pth;
}
let pth = make_path(~"foo.c");
- {
- pth.open_writer(io::Create).write(bytes!("int main() { return 0; }"));
- }
+ file::create(&pth).write(bytes!("int main() { return 0; }"));
let db_path = make_path(~"db.json");
@@ -511,7 +507,7 @@ fn test() {
let subcx = cx.clone();
let pth = pth.clone();
- let file_content = from_utf8_owned(pth.open_reader(io::Open).read_to_end());
+ let file_content = from_utf8_owned(file::open(&pth).read_to_end());
// FIXME (#9639): This needs to handle non-utf8 paths
prep.declare_input("file", pth.as_str().unwrap(), file_content);
diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs
index 815ec943c4962..7d044ba998fdb 100644
--- a/src/librustc/back/link.rs
+++ b/src/librustc/back/link.rs
@@ -27,12 +27,11 @@ use std::char;
use std::hash::Streaming;
use std::hash;
use std::os::consts::{macos, freebsd, linux, android, win32};
-use std::os;
use std::ptr;
-use std::rt::io::Writer;
use std::run;
use std::str;
use std::vec;
+use std::rt::io::file;
use syntax::ast;
use syntax::ast_map::{path, path_mod, path_name, path_pretty_name};
use syntax::attr;
@@ -951,20 +950,18 @@ pub fn link_binary(sess: Session,
// Remove the temporary object file if we aren't saving temps
if !sess.opts.save_temps {
- if ! os::remove_file(obj_filename) {
- sess.warn(format!("failed to delete object file `{}`",
- obj_filename.display()));
- }
+ file::unlink(obj_filename);
}
}
fn is_writeable(p: &Path) -> bool {
+ use std::rt::io;
use std::libc::consts::os::posix88::S_IWUSR;
- !os::path_exists(p) ||
- (match p.get_mode() {
- None => false,
- Some(m) => m & S_IWUSR as uint == S_IWUSR as uint
+ !p.exists() ||
+ (match io::result(|| p.stat()) {
+ Err(*) => false,
+ Ok(m) => (m.mode as uint) & S_IWUSR as uint == S_IWUSR as uint
})
}
diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs
index fb593b56e15f5..1526b5ad9c66a 100644
--- a/src/librustc/driver/driver.rs
+++ b/src/librustc/driver/driver.rs
@@ -27,6 +27,7 @@ use util::ppaux;
use std::hashmap::{HashMap,HashSet};
use std::rt::io;
+use std::rt::io::file;
use std::rt::io::mem::MemReader;
use std::os;
use std::vec;
@@ -369,7 +370,7 @@ pub fn phase_5_run_llvm_passes(sess: Session,
// Remove assembly source unless --save-temps was specified
if !sess.opts.save_temps {
- os::remove_file(&asm_filename);
+ file::unlink(&asm_filename);
}
} else {
time(sess.time_passes(), "LLVM passes", (), |_|
diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs
index 94dfc006076f9..44e43bd4ef3a6 100644
--- a/src/librustc/metadata/filesearch.rs
+++ b/src/librustc/metadata/filesearch.rs
@@ -11,6 +11,8 @@
use std::option;
use std::os;
+use std::rt::io;
+use std::rt::io::file;
use std::hashmap::HashSet;
pub enum FileMatch { FileMatches, FileDoesntMatch }
@@ -117,22 +119,26 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
pub fn search(filesearch: @FileSearch, pick: pick) {
do filesearch.for_each_lib_search_path() |lib_search_path| {
debug!("searching {}", lib_search_path.display());
- let r = os::list_dir_path(lib_search_path);
- let mut rslt = FileDoesntMatch;
- for path in r.iter() {
- debug!("testing {}", path.display());
- let maybe_picked = pick(path);
- match maybe_picked {
- FileMatches => {
- debug!("picked {}", path.display());
- rslt = FileMatches;
- }
- FileDoesntMatch => {
- debug!("rejected {}", path.display());
+ match io::result(|| file::readdir(lib_search_path)) {
+ Ok(files) => {
+ let mut rslt = FileDoesntMatch;
+ for path in files.iter() {
+ debug!("testing {}", path.display());
+ let maybe_picked = pick(path);
+ match maybe_picked {
+ FileMatches => {
+ debug!("picked {}", path.display());
+ rslt = FileMatches;
+ }
+ FileDoesntMatch => {
+ debug!("rejected {}", path.display());
+ }
+ }
}
+ rslt
}
+ Err(*) => FileDoesntMatch,
}
- rslt
};
}
@@ -210,7 +216,7 @@ pub fn rust_path() -> ~[Path] {
break
}
cwd.set_filename(".rust");
- if !env_rust_path.contains(&cwd) && os::path_exists(&cwd) {
+ if !env_rust_path.contains(&cwd) && cwd.exists() {
env_rust_path.push(cwd.clone());
}
cwd.pop();
@@ -218,7 +224,7 @@ pub fn rust_path() -> ~[Path] {
let h = os::homedir();
for h in h.iter() {
let p = h.join(".rust");
- if !env_rust_path.contains(&p) && os::path_exists(&p) {
+ if !env_rust_path.contains(&p) && p.exists() {
env_rust_path.push(p);
}
}
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 7bfe0910252be..fd7ba7c045277 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -40,10 +40,8 @@ use std::fmt;
use std::hashmap::{HashMap, HashSet};
use std::local_data;
use std::rt::io::buffered::BufferedWriter;
-use std::rt::io::file::{FileInfo, DirectoryInfo};
-use std::rt::io::file;
use std::rt::io;
-use std::rt::io::Reader;
+use std::rt::io::file;
use std::os;
use std::str;
use std::task;
@@ -265,8 +263,8 @@ pub fn run(mut crate: clean::Crate, dst: Path) {
// Publish the search index
{
dst.push("search-index.js");
- let mut w = BufferedWriter::new(dst.open_writer(io::CreateOrTruncate));
- let w = &mut w as &mut io::Writer;
+ let mut w = BufferedWriter::new(file::create(&dst).unwrap());
+ let w = &mut w as &mut Writer;
write!(w, "var searchIndex = [");
for (i, item) in cache.search_index.iter().enumerate() {
if i > 0 { write!(w, ","); }
@@ -315,8 +313,7 @@ pub fn run(mut crate: clean::Crate, dst: Path) {
/// Writes the entire contents of a string to a destination, not attempting to
/// catch any errors.
fn write(dst: Path, contents: &str) {
- let mut w = dst.open_writer(io::CreateOrTruncate);
- w.write(contents.as_bytes());
+ file::create(&dst).write(contents.as_bytes());
}
/// Makes a directory on the filesystem, failing the task if an error occurs and
@@ -328,7 +325,7 @@ fn mkdir(path: &Path) {
fail!()
}).inside {
if !path.is_dir() {
- file::mkdir(path);
+ file::mkdir(path, io::UserRWX);
}
}
}
@@ -419,16 +416,13 @@ impl<'self> SourceCollector<'self> {
let mut contents = ~[];
{
let mut buf = [0, ..1024];
- let r = do io::io_error::cond.trap(|_| {}).inside {
- p.open_reader(io::Open)
- };
// If we couldn't open this file, then just returns because it
// probably means that it's some standard library macro thing and we
// can't have the source to it anyway.
- let mut r = match r {
- Some(r) => r,
+ let mut r = match io::result(|| file::open(&p)) {
+ Ok(r) => r,
// eew macro hacks
- None => return filename == ""
+ Err(*) => return filename == ""
};
// read everything
@@ -451,8 +445,7 @@ impl<'self> SourceCollector<'self> {
}
cur.push(p.filename().expect("source has no filename") + bytes!(".html"));
- let w = cur.open_writer(io::CreateOrTruncate);
- let mut w = BufferedWriter::new(w);
+ let mut w = BufferedWriter::new(file::create(&cur).unwrap());
let title = cur.filename_display().with_str(|s| format!("{} -- source", s));
let page = layout::Page {
@@ -460,7 +453,7 @@ impl<'self> SourceCollector<'self> {
ty: "source",
root_path: root_path,
};
- layout::render(&mut w as &mut io::Writer, &self.cx.layout,
+ layout::render(&mut w as &mut Writer, &self.cx.layout,
&page, &(""), &Source(contents.as_slice()));
w.flush();
return true;
@@ -774,7 +767,7 @@ impl Context {
///
/// The rendering driver uses this closure to queue up more work.
fn item(&mut self, item: clean::Item, f: &fn(&mut Context, clean::Item)) {
- fn render(w: io::file::FileWriter, cx: &mut Context, it: &clean::Item,
+ fn render(w: file::FileWriter, cx: &mut Context, it: &clean::Item,
pushname: bool) {
// A little unfortunate that this is done like this, but it sure
// does make formatting *a lot* nicer.
@@ -796,7 +789,7 @@ impl Context {
// of the pain by using a buffered writer instead of invoking the
// write sycall all the time.
let mut writer = BufferedWriter::new(w);
- layout::render(&mut writer as &mut io::Writer, &cx.layout, &page,
+ layout::render(&mut writer as &mut Writer, &cx.layout, &page,
&Sidebar{ cx: cx, item: it },
&Item{ cx: cx, item: it });
writer.flush();
@@ -811,8 +804,7 @@ impl Context {
do self.recurse(name) |this| {
let item = item.take();
let dst = this.dst.join("index.html");
- let writer = dst.open_writer(io::CreateOrTruncate);
- render(writer.unwrap(), this, &item, false);
+ render(file::create(&dst).unwrap(), this, &item, false);
let m = match item.inner {
clean::ModuleItem(m) => m,
@@ -829,8 +821,7 @@ impl Context {
// pages dedicated to them.
_ if item.name.is_some() => {
let dst = self.dst.join(item_path(&item));
- let writer = dst.open_writer(io::CreateOrTruncate);
- render(writer.unwrap(), self, &item, true);
+ render(file::create(&dst).unwrap(), self, &item, true);
}
_ => {}
@@ -967,7 +958,7 @@ fn shorter<'a>(s: Option<&'a str>) -> &'a str {
}
}
-fn document(w: &mut io::Writer, item: &clean::Item) {
+fn document(w: &mut Writer, item: &clean::Item) {
match item.doc_value() {
Some(s) => {
write!(w, "{}
", Markdown(s));
@@ -976,7 +967,7 @@ fn document(w: &mut io::Writer, item: &clean::Item) {
}
}
-fn item_module(w: &mut io::Writer, cx: &Context,
+fn item_module(w: &mut Writer, cx: &Context,
item: &clean::Item, items: &[clean::Item]) {
document(w, item);
debug!("{:?}", items);
@@ -1123,7 +1114,7 @@ fn item_module(w: &mut io::Writer, cx: &Context,
write!(w, "");
}
-fn item_function(w: &mut io::Writer, it: &clean::Item, f: &clean::Function) {
+fn item_function(w: &mut Writer, it: &clean::Item, f: &clean::Function) {
write!(w, "{vis}{purity}fn {name}{generics}{decl}
",
vis = VisSpace(it.visibility),
purity = PuritySpace(f.purity),
@@ -1133,7 +1124,7 @@ fn item_function(w: &mut io::Writer, it: &clean::Item, f: &clean::Function) {
document(w, it);
}
-fn item_trait(w: &mut io::Writer, it: &clean::Item, t: &clean::Trait) {
+fn item_trait(w: &mut Writer, it: &clean::Item, t: &clean::Trait) {
let mut parents = ~"";
if t.parents.len() > 0 {
parents.push_str(": ");
@@ -1176,7 +1167,7 @@ fn item_trait(w: &mut io::Writer, it: &clean::Item, t: &clean::Trait) {
// Trait documentation
document(w, it);
- fn meth(w: &mut io::Writer, m: &clean::TraitMethod) {
+ fn meth(w: &mut Writer, m: &clean::TraitMethod) {
write!(w, "",
shortty(m.item()),
*m.item().name.get_ref());
@@ -1234,8 +1225,8 @@ fn item_trait(w: &mut io::Writer, it: &clean::Item, t: &clean::Trait) {
}
}
-fn render_method(w: &mut io::Writer, meth: &clean::Item, withlink: bool) {
- fn fun(w: &mut io::Writer, it: &clean::Item, purity: ast::purity,
+fn render_method(w: &mut Writer, meth: &clean::Item, withlink: bool) {
+ fn fun(w: &mut Writer, it: &clean::Item, purity: ast::purity,
g: &clean::Generics, selfty: &clean::SelfTy, d: &clean::FnDecl,
withlink: bool) {
write!(w, "{}fn {withlink, select,
@@ -1264,7 +1255,7 @@ fn render_method(w: &mut io::Writer, meth: &clean::Item, withlink: bool) {
}
}
-fn item_struct(w: &mut io::Writer, it: &clean::Item, s: &clean::Struct) {
+fn item_struct(w: &mut Writer, it: &clean::Item, s: &clean::Struct) {
write!(w, "");
render_struct(w, it, Some(&s.generics), s.struct_type, s.fields,
s.fields_stripped, "", true);
@@ -1288,7 +1279,7 @@ fn item_struct(w: &mut io::Writer, it: &clean::Item, s: &clean::Struct) {
render_methods(w, it);
}
-fn item_enum(w: &mut io::Writer, it: &clean::Item, e: &clean::Enum) {
+fn item_enum(w: &mut Writer, it: &clean::Item, e: &clean::Enum) {
write!(w, "{}enum {}{}",
VisSpace(it.visibility),
it.name.get_ref().as_slice(),
@@ -1365,7 +1356,7 @@ fn item_enum(w: &mut io::Writer, it: &clean::Item, e: &clean::Enum) {
render_methods(w, it);
}
-fn render_struct(w: &mut io::Writer, it: &clean::Item,
+fn render_struct(w: &mut Writer, it: &clean::Item,
g: Option<&clean::Generics>,
ty: doctree::StructType,
fields: &[clean::Item],
@@ -1418,7 +1409,7 @@ fn render_struct(w: &mut io::Writer, it: &clean::Item,
}
}
-fn render_methods(w: &mut io::Writer, it: &clean::Item) {
+fn render_methods(w: &mut Writer, it: &clean::Item) {
do local_data::get(cache_key) |cache| {
let cache = cache.unwrap();
do cache.read |c| {
@@ -1453,7 +1444,7 @@ fn render_methods(w: &mut io::Writer, it: &clean::Item) {
}
}
-fn render_impl(w: &mut io::Writer, i: &clean::Impl, dox: &Option<~str>) {
+fn render_impl(w: &mut Writer, i: &clean::Impl, dox: &Option<~str>) {
write!(w, "impl{} ", i.generics);
let trait_id = match i.trait_ {
Some(ref ty) => {
@@ -1474,7 +1465,7 @@ fn render_impl(w: &mut io::Writer, i: &clean::Impl, dox: &Option<~str>) {
None => {}
}
- fn docmeth(w: &mut io::Writer, item: &clean::Item) -> bool {
+ fn docmeth(w: &mut Writer, item: &clean::Item) -> bool {
write!(w, "",
*item.name.get_ref());
render_method(w, item, false);
@@ -1552,7 +1543,7 @@ fn render_impl(w: &mut io::Writer, i: &clean::Impl, dox: &Option<~str>) {
write!(w, "");
}
-fn item_typedef(w: &mut io::Writer, it: &clean::Item, t: &clean::Typedef) {
+fn item_typedef(w: &mut Writer, it: &clean::Item, t: &clean::Typedef) {
write!(w, "type {}{} = {};
",
it.name.get_ref().as_slice(),
t.generics,
@@ -1574,7 +1565,7 @@ impl<'self> fmt::Default for Sidebar<'self> {
}
write!(fmt.buf, "
");
- fn block(w: &mut io::Writer, short: &str, longty: &str,
+ fn block(w: &mut Writer, short: &str, longty: &str,
cur: &clean::Item, cx: &Context) {
let items = match cx.sidebar.find_equiv(&short) {
Some(items) => items.as_slice(),
diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs
index 770d535c6ea9e..7a64ca6d6fc2a 100644
--- a/src/librustdoc/lib.rs
+++ b/src/librustdoc/lib.rs
@@ -25,9 +25,8 @@ extern mod extra;
use std::cell::Cell;
use std::local_data;
-use std::rt::io::Writer;
-use std::rt::io::file::FileInfo;
use std::rt::io;
+use std::rt::io::file;
use std::rt::io::mem::MemWriter;
use std::rt::io::Decorator;
use std::str;
@@ -260,7 +259,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
/// This input format purely deserializes the json output file. No passes are
/// run over the deserialized output.
fn json_input(input: &str) -> Result