Skip to content

Commit 658637b

Browse files
committed
auto merge of #10179 : alexcrichton/rust/rt-improvements, r=cmr
This fleshes out the io::file module a fair bit more, adding all of the functionality that I can think of that we would want. Some questions about the representation which I'm curious about: * I modified `FileStat` to be a little less platform-agnostic, but it's still fairly platform-specific. I don't want to hide information that we have, but I don't want to depend on this information being available. One possible route is to have an `extra` field which has all this os-dependent stuff which is clearly documented as it should be avoided. * Does it make sense for directory functions to be top-level functions instead of static methods? It seems silly to import `std::rt::io::file` and `std::rt::io::File` at the top of files that need to deal with directories and files.
2 parents 70e9b5a + 3c3ed14 commit 658637b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2724
-2450
lines changed

mk/tests.mk

+3-3
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ CTEST_BUILD_BASE_rpass = run-pass
517517
CTEST_MODE_rpass = run-pass
518518
CTEST_RUNTOOL_rpass = $(CTEST_RUNTOOL)
519519

520-
CTEST_SRC_BASE_rpass-full = run-pass-full
521-
CTEST_BUILD_BASE_rpass-full = run-pass-full
520+
CTEST_SRC_BASE_rpass-full = run-pass-fulldeps
521+
CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps
522522
CTEST_MODE_rpass-full = run-pass
523523
CTEST_RUNTOOL_rpass-full = $(CTEST_RUNTOOL)
524524

@@ -673,7 +673,7 @@ PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
673673
PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
674674
PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS)
675675
PRETTY_DIRNAME_pretty-rpass = run-pass
676-
PRETTY_DIRNAME_pretty-rpass-full = run-pass-full
676+
PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps
677677
PRETTY_DIRNAME_pretty-rfail = run-fail
678678
PRETTY_DIRNAME_pretty-bench = bench
679679
PRETTY_DIRNAME_pretty-pretty = pretty

src/compiletest/compiletest.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extern mod extra;
1717

1818
use std::os;
1919
use std::rt;
20+
use std::rt::io::fs;
2021

2122
use extra::getopts;
2223
use extra::getopts::groups::{optopt, optflag, reqopt};
@@ -247,7 +248,7 @@ pub fn make_tests(config: &config) -> ~[test::TestDescAndFn] {
247248
debug!("making tests from {}",
248249
config.src_base.display());
249250
let mut tests = ~[];
250-
let dirs = os::list_dir_path(&config.src_base);
251+
let dirs = fs::readdir(&config.src_base);
251252
for file in dirs.iter() {
252253
let file = file.clone();
253254
debug!("inspecting file {}", file.display());

src/compiletest/errors.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use std::rt::io::buffered::BufferedReader;
12+
use std::rt::io::File;
13+
1114
pub struct ExpectedError { line: uint, kind: ~str, msg: ~str }
1215

1316
// Load any test directives embedded in the file
1417
pub fn load_errors(testfile: &Path) -> ~[ExpectedError] {
15-
use std::rt::io::Open;
16-
use std::rt::io::file::FileInfo;
17-
use std::rt::io::buffered::BufferedReader;
1818

1919
let mut error_patterns = ~[];
20-
let mut rdr = BufferedReader::new(testfile.open_reader(Open).unwrap());
20+
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
2121
let mut line_num = 1u;
2222
loop {
2323
let ln = match rdr.read_line() {

src/compiletest/header.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,10 @@ pub fn is_test_ignored(config: &config, testfile: &Path) -> bool {
103103
}
104104

105105
fn iter_header(testfile: &Path, it: &fn(&str) -> bool) -> bool {
106-
use std::rt::io::Open;
107-
use std::rt::io::file::FileInfo;
108106
use std::rt::io::buffered::BufferedReader;
107+
use std::rt::io::File;
109108

110-
let mut rdr = BufferedReader::new(testfile.open_reader(Open).unwrap());
109+
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
111110
loop {
112111
let ln = match rdr.read_line() {
113112
Some(ln) => ln, None => break

src/compiletest/runtest.rs

+11-39
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,18 @@ use procsrv;
2020
use util;
2121
use util::logv;
2222

23-
use std::cell::Cell;
2423
use std::rt::io;
25-
use std::rt::io::Writer;
26-
use std::rt::io::Reader;
27-
use std::rt::io::file::FileInfo;
24+
use std::rt::io::fs;
25+
use std::rt::io::File;
2826
use std::os;
2927
use std::str;
30-
use std::task::{spawn_sched, SingleThreaded};
3128
use std::vec;
32-
use std::unstable::running_on_valgrind;
3329

3430
use extra::test::MetricMap;
3531

3632
pub fn run(config: config, testfile: ~str) {
37-
let config = Cell::new(config);
38-
let testfile = Cell::new(testfile);
39-
// FIXME #6436: Creating another thread to run the test because this
40-
// is going to call waitpid. The new scheduler has some strange
41-
// interaction between the blocking tasks and 'friend' schedulers
42-
// that destroys parallelism if we let normal schedulers block.
43-
// It should be possible to remove this spawn once std::run is
44-
// rewritten to be non-blocking.
45-
//
46-
// We do _not_ create another thread if we're running on V because
47-
// it serializes all threads anyways.
48-
if running_on_valgrind() {
49-
let config = config.take();
50-
let testfile = testfile.take();
51-
let mut _mm = MetricMap::new();
52-
run_metrics(config, testfile, &mut _mm);
53-
} else {
54-
do spawn_sched(SingleThreaded) {
55-
let config = config.take();
56-
let testfile = testfile.take();
57-
let mut _mm = MetricMap::new();
58-
run_metrics(config, testfile, &mut _mm);
59-
}
60-
}
33+
let mut _mm = MetricMap::new();
34+
run_metrics(config, testfile, &mut _mm);
6135
}
6236

6337
pub fn run_metrics(config: config, testfile: ~str, mm: &mut MetricMap) {
@@ -173,7 +147,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
173147
let rounds =
174148
match props.pp_exact { Some(_) => 1, None => 2 };
175149

176-
let src = testfile.open_reader(io::Open).read_to_end();
150+
let src = File::open(testfile).read_to_end();
177151
let src = str::from_utf8_owned(src);
178152
let mut srcs = ~[src];
179153

@@ -195,7 +169,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
195169
let mut expected = match props.pp_exact {
196170
Some(ref file) => {
197171
let filepath = testfile.dir_path().join(file);
198-
let s = filepath.open_reader(io::Open).read_to_end();
172+
let s = File::open(&filepath).read_to_end();
199173
str::from_utf8_owned(s)
200174
}
201175
None => { srcs[srcs.len() - 2u].clone() }
@@ -651,10 +625,8 @@ fn compose_and_run_compiler(
651625
}
652626

653627
fn ensure_dir(path: &Path) {
654-
if os::path_is_dir(path) { return; }
655-
if !os::make_dir(path, 0x1c0i32) {
656-
fail!("can't make dir {}", path.display());
657-
}
628+
if path.is_dir() { return; }
629+
fs::mkdir(path, io::UserRWX);
658630
}
659631

660632
fn compose_and_run(config: &config, testfile: &Path,
@@ -768,7 +740,7 @@ fn dump_output(config: &config, testfile: &Path, out: &str, err: &str) {
768740
fn dump_output_file(config: &config, testfile: &Path,
769741
out: &str, extension: &str) {
770742
let outfile = make_out_name(config, testfile, extension);
771-
outfile.open_writer(io::CreateOrTruncate).write(out.as_bytes());
743+
File::create(&outfile).write(out.as_bytes());
772744
}
773745

774746
fn make_out_name(config: &config, testfile: &Path, extension: &str) -> Path {
@@ -924,7 +896,7 @@ fn _dummy_exec_compiled_test(config: &config, props: &TestProps,
924896
fn _arm_push_aux_shared_library(config: &config, testfile: &Path) {
925897
let tdir = aux_output_dir_name(config, testfile);
926898

927-
let dirs = os::list_dir_path(&tdir);
899+
let dirs = fs::readdir(&tdir);
928900
for file in dirs.iter() {
929901
if file.extension_str() == Some("so") {
930902
// FIXME (#9639): This needs to handle non-utf8 paths
@@ -1019,7 +991,7 @@ fn disassemble_extract(config: &config, _props: &TestProps,
1019991

1020992

1021993
fn count_extracted_lines(p: &Path) -> uint {
1022-
let x = p.with_extension("ll").open_reader(io::Open).read_to_end();
994+
let x = File::open(&p.with_extension("ll")).read_to_end();
1023995
let x = str::from_utf8_owned(x);
1024996
x.line_iter().len()
1025997
}

src/etc/libc.c

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ void posix88_consts() {
143143
put_const(S_IFBLK, int);
144144
put_const(S_IFDIR, int);
145145
put_const(S_IFREG, int);
146+
put_const(S_IFLNK, int);
146147
put_const(S_IFMT, int);
147148

148149
put_const(S_IEXEC, int);

src/libextra/glob.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525

2626
use std::{os, path};
27+
use std::rt::io;
28+
use std::rt::io::fs;
2729
use std::path::is_sep;
2830

2931
use sort;
@@ -146,9 +148,14 @@ impl Iterator<Path> for GlobIterator {
146148
}
147149

148150
fn list_dir_sorted(path: &Path) -> ~[Path] {
149-
let mut children = os::list_dir_path(path);
150-
sort::quick_sort(children, |p1, p2| p2.filename().unwrap() <= p1.filename().unwrap());
151-
children
151+
match io::result(|| fs::readdir(path)) {
152+
Ok(children) => {
153+
let mut children = children;
154+
sort::quick_sort(children, |p1, p2| p2.filename() <= p1.filename());
155+
children
156+
}
157+
Err(*) => ~[]
158+
}
152159
}
153160

154161
/**

src/libextra/tempfile.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use std::os;
1515
use std::rand::Rng;
1616
use std::rand;
17+
use std::rt::io;
18+
use std::rt::io::fs;
1719

1820
/// A wrapper for a path to temporary directory implementing automatic
1921
/// scope-pased deletion.
@@ -36,8 +38,9 @@ impl TempDir {
3638
let mut r = rand::rng();
3739
for _ in range(0u, 1000) {
3840
let p = tmpdir.join(r.gen_ascii_str(16) + suffix);
39-
if os::make_dir(&p, 0x1c0) { // 700
40-
return Some(TempDir { path: Some(p) });
41+
match io::result(|| fs::mkdir(&p, io::UserRWX)) {
42+
Err(*) => {}
43+
Ok(()) => return Some(TempDir { path: Some(p) })
4144
}
4245
}
4346
None
@@ -69,7 +72,9 @@ impl TempDir {
6972
impl Drop for TempDir {
7073
fn drop(&mut self) {
7174
for path in self.path.iter() {
72-
os::remove_dir_recursive(path);
75+
if path.exists() {
76+
fs::rmdir_recursive(path);
77+
}
7378
}
7479
}
7580
}

src/libextra/terminfo/parser/compiled.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,6 @@ mod test {
329329
#[ignore(reason = "no ncurses on buildbots, needs a bundled terminfo file to test against")]
330330
fn test_parse() {
331331
// FIXME #6870: Distribute a compiled file in src/tests and test there
332-
// parse(io::file_reader(&p("/usr/share/terminfo/r/rxvt-256color")).unwrap(), false);
332+
// parse(io::fs_reader(&p("/usr/share/terminfo/r/rxvt-256color")).unwrap(), false);
333333
}
334334
}

src/libextra/terminfo/searcher.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use std::{os, str};
1515
use std::os::getenv;
1616
use std::rt::io;
17-
use std::rt::io::file::FileInfo;
17+
use std::rt::io::File;
1818

1919
/// Return path to database entry for `term`
2020
pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
@@ -56,16 +56,16 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
5656

5757
// Look for the terminal in all of the search directories
5858
for p in dirs_to_search.iter() {
59-
if os::path_exists(p) {
59+
if p.exists() {
6060
let f = str::from_char(first_char);
6161
let newp = p.join_many([f.as_slice(), term]);
62-
if os::path_exists(&newp) {
62+
if newp.exists() {
6363
return Some(~newp);
6464
}
6565
// on some installations the dir is named after the hex of the char (e.g. OS X)
6666
let f = format!("{:x}", first_char as uint);
6767
let newp = p.join_many([f.as_slice(), term]);
68-
if os::path_exists(&newp) {
68+
if newp.exists() {
6969
return Some(~newp);
7070
}
7171
}
@@ -76,7 +76,7 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
7676
/// Return open file for `term`
7777
pub fn open(term: &str) -> Result<@mut io::Reader, ~str> {
7878
match get_dbpath_for_term(term) {
79-
Some(x) => Ok(@mut x.open_reader(io::Open).unwrap() as @mut io::Reader),
79+
Some(x) => Ok(@mut File::open(x) as @mut io::Reader),
8080
None => Err(format!("could not find terminfo entry for {}", term))
8181
}
8282
}

src/libextra/test.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use treemap::TreeMap;
3131
use std::clone::Clone;
3232
use std::comm::{stream, SharedChan, GenericPort, GenericChan};
3333
use std::rt::io;
34-
use std::rt::io::file::FileInfo;
34+
use std::rt::io::File;
3535
use std::task;
3636
use std::to_str::ToStr;
3737
use std::f64;
@@ -353,10 +353,7 @@ struct ConsoleTestState {
353353
impl ConsoleTestState {
354354
pub fn new(opts: &TestOpts) -> ConsoleTestState {
355355
let log_out = match opts.logfile {
356-
Some(ref path) => {
357-
let out = path.open_writer(io::CreateOrTruncate);
358-
Some(@mut out as @mut io::Writer)
359-
},
356+
Some(ref path) => Some(@mut File::create(path) as @mut io::Writer),
360357
None => None
361358
};
362359
let out = @mut io::stdio::stdout() as @mut io::Writer;
@@ -938,16 +935,15 @@ impl MetricMap {
938935
939936
/// Load MetricDiff from a file.
940937
pub fn load(p: &Path) -> MetricMap {
941-
assert!(os::path_exists(p));
942-
let f = @mut p.open_reader(io::Open) as @mut io::Reader;
938+
assert!(p.exists());
939+
let f = @mut File::open(p) as @mut io::Reader;
943940
let mut decoder = json::Decoder(json::from_reader(f).unwrap());
944941
MetricMap(Decodable::decode(&mut decoder))
945942
}
946943
947944
/// Write MetricDiff to a file.
948945
pub fn save(&self, p: &Path) {
949-
let f = @mut p.open_writer(io::CreateOrTruncate);
950-
self.to_json().to_pretty_writer(f as @mut io::Writer);
946+
self.to_json().to_pretty_writer(@mut File::create(p) as @mut io::Writer);
951947
}
952948
953949
/// Compare against another MetricMap. Optionally compare all
@@ -1032,7 +1028,7 @@ impl MetricMap {
10321028
/// `MetricChange`s are `Regression`. Returns the diff as well
10331029
/// as a boolean indicating whether the ratchet succeeded.
10341030
pub fn ratchet(&self, p: &Path, pct: Option<f64>) -> (MetricDiff, bool) {
1035-
let old = if os::path_exists(p) {
1031+
let old = if p.exists() {
10361032
MetricMap::load(p)
10371033
} else {
10381034
MetricMap::new()

src/libextra/uuid.rs

-1
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,6 @@ mod test {
792792

793793
#[test]
794794
fn test_serialize_round_trip() {
795-
use std;
796795
use ebml;
797796
use serialize::{Encodable, Decodable};
798797

0 commit comments

Comments
 (0)