Skip to content

Commit 9c18510

Browse files
committed
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
1 parent 7bf58c2 commit 9c18510

Some content is hidden

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

57 files changed

+1363
-1492
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::file;
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 = file::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

+8-12
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ use util::logv;
2222

2323
use std::cell::Cell;
2424
use std::rt::io;
25-
use std::rt::io::Writer;
26-
use std::rt::io::Reader;
27-
use std::rt::io::file::FileInfo;
25+
use std::rt::io::file;
2826
use std::os;
2927
use std::str;
3028
use std::task::{spawn_sched, SingleThreaded};
@@ -173,7 +171,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
173171
let rounds =
174172
match props.pp_exact { Some(_) => 1, None => 2 };
175173

176-
let src = testfile.open_reader(io::Open).read_to_end();
174+
let src = file::open(testfile).read_to_end();
177175
let src = str::from_utf8_owned(src);
178176
let mut srcs = ~[src];
179177

@@ -195,7 +193,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
195193
let mut expected = match props.pp_exact {
196194
Some(ref file) => {
197195
let filepath = testfile.dir_path().join(file);
198-
let s = filepath.open_reader(io::Open).read_to_end();
196+
let s = file::open(&filepath).read_to_end();
199197
str::from_utf8_owned(s)
200198
}
201199
None => { srcs[srcs.len() - 2u].clone() }
@@ -651,10 +649,8 @@ fn compose_and_run_compiler(
651649
}
652650

653651
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-
}
652+
if path.is_dir() { return; }
653+
file::mkdir(path, io::UserRWX);
658654
}
659655

660656
fn compose_and_run(config: &config, testfile: &Path,
@@ -768,7 +764,7 @@ fn dump_output(config: &config, testfile: &Path, out: &str, err: &str) {
768764
fn dump_output_file(config: &config, testfile: &Path,
769765
out: &str, extension: &str) {
770766
let outfile = make_out_name(config, testfile, extension);
771-
outfile.open_writer(io::CreateOrTruncate).write(out.as_bytes());
767+
file::create(&outfile).write(out.as_bytes());
772768
}
773769

774770
fn make_out_name(config: &config, testfile: &Path, extension: &str) -> Path {
@@ -924,7 +920,7 @@ fn _dummy_exec_compiled_test(config: &config, props: &TestProps,
924920
fn _arm_push_aux_shared_library(config: &config, testfile: &Path) {
925921
let tdir = aux_output_dir_name(config, testfile);
926922

927-
let dirs = os::list_dir_path(&tdir);
923+
let dirs = file::readdir(&tdir);
928924
for file in dirs.iter() {
929925
if file.extension_str() == Some("so") {
930926
// FIXME (#9639): This needs to handle non-utf8 paths
@@ -1019,7 +1015,7 @@ fn disassemble_extract(config: &config, _props: &TestProps,
10191015

10201016

10211017
fn count_extracted_lines(p: &Path) -> uint {
1022-
let x = p.with_extension("ll").open_reader(io::Open).read_to_end();
1018+
let x = file::open(&p.with_extension("ll")).read_to_end();
10231019
let x = str::from_utf8_owned(x);
10241020
x.line_iter().len()
10251021
}

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::file;
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(|| file::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::file;
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(|| file::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+
file::rmdir_recursive(path);
77+
}
7378
}
7479
}
7580
}

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

src/libextra/workcache.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ use arc::{Arc,RWArc};
1717
use treemap::TreeMap;
1818
use std::cell::Cell;
1919
use std::comm::{PortOne, oneshot};
20-
use std::{os, str, task};
20+
use std::{str, task};
2121
use std::rt::io;
22-
use std::rt::io::Writer;
23-
use std::rt::io::Reader;
22+
use std::rt::io::file;
2423
use std::rt::io::Decorator;
2524
use std::rt::io::mem::MemWriter;
26-
use std::rt::io::file::FileInfo;
2725

2826
/**
2927
*
@@ -145,7 +143,7 @@ impl Database {
145143
db_cache: TreeMap::new(),
146144
db_dirty: false
147145
};
148-
if os::path_exists(&rslt.db_filename) {
146+
if rslt.db_filename.exists() {
149147
rslt.load();
150148
}
151149
rslt
@@ -178,19 +176,19 @@ impl Database {
178176

179177
// FIXME #4330: This should have &mut self and should set self.db_dirty to false.
180178
fn save(&self) {
181-
let f = @mut self.db_filename.open_writer(io::CreateOrTruncate);
179+
let f = @mut file::create(&self.db_filename);
182180
self.db_cache.to_json().to_pretty_writer(f as @mut io::Writer);
183181
}
184182

185183
fn load(&mut self) {
186184
assert!(!self.db_dirty);
187-
assert!(os::path_exists(&self.db_filename));
188-
let f = self.db_filename.open_reader(io::Open);
189-
match f {
190-
None => fail!("Couldn't load workcache database {}",
191-
self.db_filename.display()),
192-
Some(r) =>
193-
match json::from_reader(@mut r as @mut io::Reader) {
185+
assert!(self.db_filename.exists());
186+
match io::result(|| file::open(&self.db_filename)) {
187+
Err(e) => fail!("Couldn't load workcache database {}: {}",
188+
self.db_filename.display(),
189+
e.desc),
190+
Ok(r) =>
191+
match json::from_reader(@mut r.unwrap() as @mut io::Reader) {
194192
Err(e) => fail!("Couldn't parse workcache database (from file {}): {}",
195193
self.db_filename.display(), e.to_str()),
196194
Ok(r) => {
@@ -482,23 +480,21 @@ impl<'self, T:Send +
482480
#[test]
483481
fn test() {
484482
use std::{os, run};
485-
use std::rt::io::Reader;
483+
use std::rt::io::file;
486484
use std::str::from_utf8_owned;
487485

488486
// Create a path to a new file 'filename' in the directory in which
489487
// this test is running.
490488
fn make_path(filename: ~str) -> Path {
491489
let pth = os::self_exe_path().expect("workcache::test failed").with_filename(filename);
492-
if os::path_exists(&pth) {
493-
os::remove_file(&pth);
490+
if pth.exists() {
491+
file::unlink(&pth);
494492
}
495493
return pth;
496494
}
497495

498496
let pth = make_path(~"foo.c");
499-
{
500-
pth.open_writer(io::Create).write(bytes!("int main() { return 0; }"));
501-
}
497+
file::create(&pth).write(bytes!("int main() { return 0; }"));
502498

503499
let db_path = make_path(~"db.json");
504500

@@ -511,7 +507,7 @@ fn test() {
511507
let subcx = cx.clone();
512508
let pth = pth.clone();
513509

514-
let file_content = from_utf8_owned(pth.open_reader(io::Open).read_to_end());
510+
let file_content = from_utf8_owned(file::open(&pth).read_to_end());
515511

516512
// FIXME (#9639): This needs to handle non-utf8 paths
517513
prep.declare_input("file", pth.as_str().unwrap(), file_content);

0 commit comments

Comments
 (0)