From 7d268cb34ad562b45103f3c9fd4a67bc2a96019d Mon Sep 17 00:00:00 2001
From: Alex Crichton
Date: Fri, 25 Oct 2013 16:48:26 -0700
Subject: [PATCH 1/3] 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 6f7d868c27575a77313edc44709dd40ddd596ba6 Mon Sep 17 00:00:00 2001
From: Alex Crichton
Date: Fri, 25 Oct 2013 16:50:08 -0700
Subject: [PATCH 2/3] 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/libstd/rt/rtio.rs | 3 ++-
src/libstd/rt/uv/file.rs | 15 +++++++++++++++
src/libstd/rt/uv/uvio.rs | 16 ++++++++++++----
src/libstd/rt/uv/uvll.rs | 8 ++++++++
src/rt/rust_uv.cpp | 5 +++++
src/rt/rustrt.def.in | 1 +
6 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs
index 366388063d4ef..928ec1a2318f5 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/libstd/rt/uv/file.rs b/src/libstd/rt/uv/file.rs
index d2ca15959b025..976913cb34a81 100644
--- a/src/libstd/rt/uv/file.rs
+++ b/src/libstd/rt/uv/file.rs
@@ -207,6 +207,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/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs
index 2d3ecbbd68907..3d3dbfbaa8b20 100644
--- a/src/libstd/rt/uv/uvio.rs
+++ b/src/libstd/rt/uv/uvio.rs
@@ -37,7 +37,7 @@ use rt::uv::addrinfo::{GetAddrInfoRequest, accum_addrinfo};
use unstable::sync::Exclusive;
use path::{GenericPath, Path};
use libc::{lseek, off_t, O_CREAT, O_APPEND, O_TRUNC, O_RDWR, O_RDONLY, O_WRONLY,
- S_IRUSR, S_IWUSR, S_IRWXU};
+ S_IRUSR, S_IWUSR};
use rt::io::{FileMode, FileAccess, OpenOrCreate, Open, Create,
CreateOrTruncate, Append, Truncate, Read, Write, ReadWrite,
FileStat};
@@ -697,10 +697,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)
};
}
@@ -712,6 +711,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/libstd/rt/uv/uvll.rs b/src/libstd/rt/uv/uvll.rs
index 2964eb9c58be3..723ed82bf14b5 100644
--- a/src/libstd/rt/uv/uvll.rs
+++ b/src/libstd/rt/uv/uvll.rs
@@ -809,6 +809,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/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) {
diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in
index 47c9554daa018..70fdc3fcbd187 100644
--- a/src/rt/rustrt.def.in
+++ b/src/rt/rustrt.def.in
@@ -116,6 +116,7 @@ rust_uv_populate_uv_stat
rust_uv_fs_mkdir
rust_uv_fs_rmdir
rust_uv_fs_readdir
+rust_uv_fs_rename
rust_dbg_lock_create
rust_dbg_lock_destroy
rust_dbg_lock_lock
From cfb481a0856cc5660bb45f3cef53abc6e370b8c1 Mon Sep 17 00:00:00 2001
From: Alex Crichton
Date: Fri, 25 Oct 2013 17:04:37 -0700
Subject: [PATCH 3/3] 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.
The api of the io::file modules has also been reworked in this commit. The
open_reader and open_writer functions have had open and create counterparts
created, neither of which take any arguments (allowing for easy usage). The
top-level 'file::open' function was renamed to 'file::open_stream', and
top-level 'file::create' and 'file::open' functions were added (same as the
methods).
I also removed the traits that add functionality to the platform's Path
structure. It was unfortunate having to import all of these traits, and it was
unclear whether they would ever be implemented for anything other than Path. For
this reason, they're now just an extra impl block on Path itself.
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.
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/rustdoc.rs | 7 +-
src/librustpkg/api.rs | 6 +-
src/librustpkg/context.rs | 3 +-
src/librustpkg/installed_packages.rs | 8 +-
src/librustpkg/package_id.rs | 1 -
src/librustpkg/package_source.rs | 17 +-
src/librustpkg/path_util.rs | 52 +-
src/librustpkg/rustpkg.rs | 31 +-
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 | 35 +-
src/librustuv/uvio.rs | 33 +-
src/librustuv/uvll.rs | 20 +-
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/rt/uv/file.rs | 22 +-
src/libstd/rt/uv/uvio.rs | 14 +-
src/libstd/rt/uv/uvll.rs | 12 +-
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/rt/rustrt.def.in | 1 +
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 +-
61 files changed, 1437 insertions(+), 1506 deletions(-)
diff --git a/mk/tests.mk b/mk/tests.mk
index 6aec4b81d0a49..277f1dfd407c5 100644
--- a/mk/tests.mk
+++ b/mk/tests.mk
@@ -503,8 +503,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)
@@ -659,7 +659,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 e7e1b11028923..718f1e527f8c3 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() }
@@ -628,10 +626,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,
@@ -745,7 +741,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 {
@@ -901,7 +897,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
@@ -996,7 +992,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 070108ddf2e8e..83af7b60002fe 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;
@@ -934,16 +931,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
@@ -1028,7 +1024,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 1b9cb10f1dcfd..30147b50ee86d 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 8aba36370d0b8..51cac5afad218 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 e92d159b5a15d..48740a1b8c3ca 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;
@@ -769,7 +762,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.
@@ -791,7 +784,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();
@@ -806,8 +799,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,
@@ -824,8 +816,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);
}
_ => {}
@@ -962,7 +953,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));
@@ -971,7 +962,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);
@@ -1118,7 +1109,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),
@@ -1128,7 +1119,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(": ");
@@ -1171,7 +1162,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());
@@ -1229,8 +1220,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,
@@ -1259,7 +1250,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);
@@ -1283,7 +1274,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(),
@@ -1360,7 +1351,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],
@@ -1413,7 +1404,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| {
@@ -1448,7 +1439,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) => {
@@ -1469,7 +1460,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);
@@ -1547,7 +1538,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,
@@ -1569,7 +1560,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/rustdoc.rs b/src/librustdoc/rustdoc.rs
index 770d535c6ea9e..7a64ca6d6fc2a 100644
--- a/src/librustdoc/rustdoc.rs
+++ b/src/librustdoc/rustdoc.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