Skip to content

Large reorgnization of rt::io::file #10086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions mk/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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());
Expand Down
8 changes: 4 additions & 4 deletions src/compiletest/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 2 additions & 3 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 8 additions & 12 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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];

Expand All @@ -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() }
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down
13 changes: 10 additions & 3 deletions src/libextra/glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/

use std::{os, path};
use std::rt::io;
use std::rt::io::file;
use std::path::is_sep;

use sort;
Expand Down Expand Up @@ -146,9 +148,14 @@ impl Iterator<Path> 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(*) => ~[]
}
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/libextra/tempfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/libextra/terminfo/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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))
}
}
Expand Down
16 changes: 6 additions & 10 deletions src/libextra/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<f64>) -> (MetricDiff, bool) {
let old = if os::path_exists(p) {
let old = if p.exists() {
MetricMap::load(p)
} else {
MetricMap::new()
Expand Down
1 change: 0 additions & 1 deletion src/libextra/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,6 @@ mod test {

#[test]
fn test_serialize_round_trip() {
use std;
use ebml;
use serialize::{Encodable, Decodable};

Expand Down
36 changes: 16 additions & 20 deletions src/libextra/workcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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");

Expand All @@ -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);
Expand Down
Loading