Skip to content

Commit 3c3ed14

Browse files
committed
Move io::file to io::fs and fns out of File
This renames the `file` module to `fs` because that more accurately describes its current purpose (manipulating the filesystem, not just files). Additionally, this adds an UnstableFileStat structure as a nested structure of FileStat to signify that the fields should not be depended on. The structure is currently flagged with #[unstable], but it's unlikely that it has much meaning. Closes #10241
1 parent f19d083 commit 3c3ed14

File tree

31 files changed

+491
-477
lines changed

31 files changed

+491
-477
lines changed

src/compiletest/compiletest.rs

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

1818
use std::os;
1919
use std::rt;
20-
use std::rt::io::file;
20+
use std::rt::io::fs;
2121

2222
use extra::getopts;
2323
use extra::getopts::groups::{optopt, optflag, reqopt};
@@ -248,7 +248,7 @@ pub fn make_tests(config: &config) -> ~[test::TestDescAndFn] {
248248
debug!("making tests from {}",
249249
config.src_base.display());
250250
let mut tests = ~[];
251-
let dirs = file::readdir(&config.src_base);
251+
let dirs = fs::readdir(&config.src_base);
252252
for file in dirs.iter() {
253253
let file = file.clone();
254254
debug!("inspecting file {}", file.display());

src/compiletest/runtest.rs

+5-30
Original file line numberDiff line numberDiff line change
@@ -20,43 +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::file;
24+
use std::rt::io::fs;
2625
use std::rt::io::File;
2726
use std::os;
2827
use std::str;
29-
use std::task::{spawn_sched, SingleThreaded};
3028
use std::vec;
31-
use std::unstable::running_on_valgrind;
3229

3330
use extra::test::MetricMap;
3431

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

6237
pub fn run_metrics(config: config, testfile: ~str, mm: &mut MetricMap) {
@@ -651,7 +626,7 @@ fn compose_and_run_compiler(
651626

652627
fn ensure_dir(path: &Path) {
653628
if path.is_dir() { return; }
654-
file::mkdir(path, io::UserRWX);
629+
fs::mkdir(path, io::UserRWX);
655630
}
656631

657632
fn compose_and_run(config: &config, testfile: &Path,
@@ -921,7 +896,7 @@ fn _dummy_exec_compiled_test(config: &config, props: &TestProps,
921896
fn _arm_push_aux_shared_library(config: &config, testfile: &Path) {
922897
let tdir = aux_output_dir_name(config, testfile);
923898

924-
let dirs = file::readdir(&tdir);
899+
let dirs = fs::readdir(&tdir);
925900
for file in dirs.iter() {
926901
if file.extension_str() == Some("so") {
927902
// FIXME (#9639): This needs to handle non-utf8 paths

src/libextra/glob.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
use std::{os, path};
2727
use std::rt::io;
28-
use std::rt::io::file;
28+
use std::rt::io::fs;
2929
use std::path::is_sep;
3030

3131
use sort;
@@ -148,7 +148,7 @@ impl Iterator<Path> for GlobIterator {
148148
}
149149

150150
fn list_dir_sorted(path: &Path) -> ~[Path] {
151-
match io::result(|| file::readdir(path)) {
151+
match io::result(|| fs::readdir(path)) {
152152
Ok(children) => {
153153
let mut children = children;
154154
sort::quick_sort(children, |p1, p2| p2.filename() <= p1.filename());

src/libextra/tempfile.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::os;
1515
use std::rand::Rng;
1616
use std::rand;
1717
use std::rt::io;
18-
use std::rt::io::file;
18+
use std::rt::io::fs;
1919

2020
/// A wrapper for a path to temporary directory implementing automatic
2121
/// scope-pased deletion.
@@ -38,7 +38,7 @@ impl TempDir {
3838
let mut r = rand::rng();
3939
for _ in range(0u, 1000) {
4040
let p = tmpdir.join(r.gen_ascii_str(16) + suffix);
41-
match io::result(|| file::mkdir(&p, io::UserRWX)) {
41+
match io::result(|| fs::mkdir(&p, io::UserRWX)) {
4242
Err(*) => {}
4343
Ok(()) => return Some(TempDir { path: Some(p) })
4444
}
@@ -73,7 +73,7 @@ impl Drop for TempDir {
7373
fn drop(&mut self) {
7474
for path in self.path.iter() {
7575
if path.exists() {
76-
file::rmdir_recursive(path);
76+
fs::rmdir_recursive(path);
7777
}
7878
}
7979
}

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/workcache.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ use std::cell::Cell;
1919
use std::comm::{PortOne, oneshot};
2020
use std::{str, task};
2121
use std::rt::io;
22-
use std::rt::io::File;
23-
use std::rt::io::Decorator;
22+
use std::rt::io::{File, Decorator};
2423
use std::rt::io::mem::MemWriter;
2524

2625
/**
@@ -480,14 +479,15 @@ impl<'self, T:Send +
480479
#[test]
481480
fn test() {
482481
use std::{os, run};
482+
use std::rt::io::fs;
483483
use std::str::from_utf8_owned;
484484

485485
// Create a path to a new file 'filename' in the directory in which
486486
// this test is running.
487487
fn make_path(filename: ~str) -> Path {
488488
let pth = os::self_exe_path().expect("workcache::test failed").with_filename(filename);
489489
if pth.exists() {
490-
File::unlink(&pth);
490+
fs::unlink(&pth);
491491
}
492492
return pth;
493493
}

src/librustc/back/link.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use std::ptr;
3131
use std::run;
3232
use std::str;
3333
use std::vec;
34-
use std::rt::io::File;
34+
use std::rt::io::fs;
3535
use syntax::ast;
3636
use syntax::ast_map::{path, path_mod, path_name, path_pretty_name};
3737
use syntax::attr;
@@ -950,7 +950,7 @@ pub fn link_binary(sess: Session,
950950

951951
// Remove the temporary object file if we aren't saving temps
952952
if !sess.opts.save_temps {
953-
File::unlink(obj_filename);
953+
fs::unlink(obj_filename);
954954
}
955955
}
956956

src/librustc/driver/driver.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use util::ppaux;
2727

2828
use std::hashmap::{HashMap,HashSet};
2929
use std::rt::io;
30-
use std::rt::io::File;
30+
use std::rt::io::fs;
3131
use std::rt::io::mem::MemReader;
3232
use std::os;
3333
use std::vec;
@@ -370,7 +370,7 @@ pub fn phase_5_run_llvm_passes(sess: Session,
370370

371371
// Remove assembly source unless --save-temps was specified
372372
if !sess.opts.save_temps {
373-
File::unlink(&asm_filename);
373+
fs::unlink(&asm_filename);
374374
}
375375
} else {
376376
time(sess.time_passes(), "LLVM passes", (), |_|

src/librustc/metadata/filesearch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use std::option;
1313
use std::os;
1414
use std::rt::io;
15-
use std::rt::io::file;
15+
use std::rt::io::fs;
1616
use std::hashmap::HashSet;
1717

1818
pub enum FileMatch { FileMatches, FileDoesntMatch }
@@ -119,7 +119,7 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
119119
pub fn search(filesearch: @FileSearch, pick: pick) {
120120
do filesearch.for_each_lib_search_path() |lib_search_path| {
121121
debug!("searching {}", lib_search_path.display());
122-
match io::result(|| file::readdir(lib_search_path)) {
122+
match io::result(|| fs::readdir(lib_search_path)) {
123123
Ok(files) => {
124124
let mut rslt = FileDoesntMatch;
125125
for path in files.iter() {

src/librustdoc/html/render.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use std::hashmap::{HashMap, HashSet};
4141
use std::local_data;
4242
use std::rt::io::buffered::BufferedWriter;
4343
use std::rt::io;
44-
use std::rt::io::file;
44+
use std::rt::io::fs;
4545
use std::rt::io::File;
4646
use std::os;
4747
use std::str;
@@ -326,7 +326,7 @@ fn mkdir(path: &Path) {
326326
fail!()
327327
}).inside {
328328
if !path.is_dir() {
329-
file::mkdir(path, io::UserRWX);
329+
fs::mkdir(path, io::UserRWX);
330330
}
331331
}
332332
}

src/librustpkg/installed_packages.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ use rustc::metadata::filesearch::rust_path;
1414
use path_util::*;
1515
use std::os;
1616
use std::rt::io;
17-
use std::rt::io::file;
17+
use std::rt::io::fs;
1818

1919
pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool {
2020
let workspaces = rust_path();
2121
for p in workspaces.iter() {
22-
let binfiles = do io::ignore_io_error { file::readdir(&p.join("bin")) };
22+
let binfiles = do io::ignore_io_error { fs::readdir(&p.join("bin")) };
2323
for exec in binfiles.iter() {
2424
// FIXME (#9639): This needs to handle non-utf8 paths
2525
match exec.filestem_str() {
@@ -31,7 +31,7 @@ pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool {
3131
}
3232
}
3333
}
34-
let libfiles = do io::ignore_io_error { file::readdir(&p.join("lib")) };
34+
let libfiles = do io::ignore_io_error { fs::readdir(&p.join("lib")) };
3535
for lib in libfiles.iter() {
3636
debug!("Full name: {}", lib.display());
3737
match has_library(lib) {
@@ -55,7 +55,7 @@ pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool {
5555
}
5656

5757
pub fn has_library(p: &Path) -> Option<~str> {
58-
let files = do io::ignore_io_error { file::readdir(p) };
58+
let files = do io::ignore_io_error { fs::readdir(p) };
5959
for path in files.iter() {
6060
if path.extension_str() == Some(os::consts::DLL_EXTENSION) {
6161
let stuff : &str = path.filestem_str().expect("has_library: weird path");

src/librustpkg/lib.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ extern mod syntax;
2727
use std::{os, result, run, str, task};
2828
use std::hashmap::HashSet;
2929
use std::rt::io;
30-
use std::rt::io::file;
31-
use std::rt::io::File;
30+
use std::rt::io::fs;
3231
pub use std::path::Path;
3332

3433
use extra::workcache;
@@ -545,7 +544,7 @@ impl CtxMethods for BuildContext {
545544
note(format!("Cleaning package {} (removing directory {})",
546545
id.to_str(), dir.display()));
547546
if dir.exists() {
548-
file::rmdir_recursive(&dir);
547+
fs::rmdir_recursive(&dir);
549548
note(format!("Removed directory {}", dir.display()));
550549
}
551550

@@ -661,8 +660,8 @@ impl CtxMethods for BuildContext {
661660

662661
for exec in subex.iter() {
663662
debug!("Copying: {} -> {}", exec.display(), sub_target_ex.display());
664-
file::mkdir_recursive(&sub_target_ex.dir_path(), io::UserRWX);
665-
File::copy(exec, &sub_target_ex);
663+
fs::mkdir_recursive(&sub_target_ex.dir_path(), io::UserRWX);
664+
fs::copy(exec, &sub_target_ex);
666665
// FIXME (#9639): This needs to handle non-utf8 paths
667666
exe_thing.discover_output("binary",
668667
sub_target_ex.as_str().unwrap(),
@@ -674,8 +673,8 @@ impl CtxMethods for BuildContext {
674673
.clone().expect(format!("I built {} but apparently \
675674
didn't install it!", lib.display()));
676675
target_lib.set_filename(lib.filename().expect("weird target lib"));
677-
file::mkdir_recursive(&target_lib.dir_path(), io::UserRWX);
678-
File::copy(lib, &target_lib);
676+
fs::mkdir_recursive(&target_lib.dir_path(), io::UserRWX);
677+
fs::copy(lib, &target_lib);
679678
debug!("3. discovering output {}", target_lib.display());
680679
exe_thing.discover_output("binary",
681680
target_lib.as_str().unwrap(),
@@ -708,10 +707,10 @@ impl CtxMethods for BuildContext {
708707
}
709708

710709
fn init(&self) {
711-
file::mkdir_recursive(&Path::new("src"), io::UserRWX);
712-
file::mkdir_recursive(&Path::new("bin"), io::UserRWX);
713-
file::mkdir_recursive(&Path::new("lib"), io::UserRWX);
714-
file::mkdir_recursive(&Path::new("build"), io::UserRWX);
710+
fs::mkdir_recursive(&Path::new("src"), io::UserRWX);
711+
fs::mkdir_recursive(&Path::new("bin"), io::UserRWX);
712+
fs::mkdir_recursive(&Path::new("lib"), io::UserRWX);
713+
fs::mkdir_recursive(&Path::new("build"), io::UserRWX);
715714
}
716715

717716
fn uninstall(&self, _id: &str, _vers: Option<~str>) {

src/librustpkg/package_source.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ extern mod extra;
1313
use target::*;
1414
use package_id::PkgId;
1515
use std::rt::io;
16-
use std::rt::io::file;
17-
use std::rt::io::File;
16+
use std::rt::io::fs;
1817
use std::os;
1918
use context::*;
2019
use crate::Crate;
@@ -302,7 +301,7 @@ impl PkgSrc {
302301
// Move clone_target to local.
303302
// First, create all ancestor directories.
304303
let moved = make_dir_rwx_recursive(&local.dir_path())
305-
&& io::result(|| File::rename(&clone_target, local)).is_ok();
304+
&& io::result(|| fs::rename(&clone_target, local)).is_ok();
306305
if moved { Some(local.clone()) }
307306
else { None }
308307
}
@@ -351,7 +350,7 @@ impl PkgSrc {
351350

352351
let prefix = self.start_dir.component_iter().len();
353352
debug!("Matching against {}", self.id.short_name);
354-
for pth in file::walk_dir(&self.start_dir) {
353+
for pth in fs::walk_dir(&self.start_dir) {
355354
let maybe_known_crate_set = match pth.filename_str() {
356355
Some(filename) if filter(filename) => match filename {
357356
"lib.rs" => Some(&mut self.libs),

0 commit comments

Comments
 (0)