Skip to content

Commit f19d083

Browse files
committed
Fill out the remaining functionality in io::file
This adds bindings to the remaining functions provided by libuv, all of which are useful operations on files which need to get exposed somehow. Some highlights: * Dropped `FileReader` and `FileWriter` and `FileStream` for one `File` type * Moved all file-related methods to be static methods under `File` * All directory related methods are still top-level functions * Created `io::FilePermission` types (backed by u32) that are what you'd expect * Created `io::FileType` and refactored `FileStat` to use FileType and FilePermission * Removed the expanding matrix of `FileMode` operations. The mode of reading a file will not have the O_CREAT flag, but a write mode will always have the O_CREAT flag. Closes #10130 Closes #10131 Closes #10121
1 parent 9c18510 commit f19d083

38 files changed

+1359
-1008
lines changed

src/compiletest/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
// except according to those terms.
1010

1111
use std::rt::io::buffered::BufferedReader;
12-
use std::rt::io::file;
12+
use std::rt::io::File;
1313

1414
pub struct ExpectedError { line: uint, kind: ~str, msg: ~str }
1515

1616
// Load any test directives embedded in the file
1717
pub fn load_errors(testfile: &Path) -> ~[ExpectedError] {
1818

1919
let mut error_patterns = ~[];
20-
let mut rdr = BufferedReader::new(file::open(testfile).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-2
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ pub fn is_test_ignored(config: &config, testfile: &Path) -> bool {
104104

105105
fn iter_header(testfile: &Path, it: &fn(&str) -> bool) -> bool {
106106
use std::rt::io::buffered::BufferedReader;
107-
use std::rt::io::file;
107+
use std::rt::io::File;
108108

109-
let mut rdr = BufferedReader::new(file::open(testfile).unwrap());
109+
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
110110
loop {
111111
let ln = match rdr.read_line() {
112112
Some(ln) => ln, None => break

src/compiletest/runtest.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use util::logv;
2323
use std::cell::Cell;
2424
use std::rt::io;
2525
use std::rt::io::file;
26+
use std::rt::io::File;
2627
use std::os;
2728
use std::str;
2829
use std::task::{spawn_sched, SingleThreaded};
@@ -171,7 +172,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
171172
let rounds =
172173
match props.pp_exact { Some(_) => 1, None => 2 };
173174

174-
let src = file::open(testfile).read_to_end();
175+
let src = File::open(testfile).read_to_end();
175176
let src = str::from_utf8_owned(src);
176177
let mut srcs = ~[src];
177178

@@ -193,7 +194,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
193194
let mut expected = match props.pp_exact {
194195
Some(ref file) => {
195196
let filepath = testfile.dir_path().join(file);
196-
let s = file::open(&filepath).read_to_end();
197+
let s = File::open(&filepath).read_to_end();
197198
str::from_utf8_owned(s)
198199
}
199200
None => { srcs[srcs.len() - 2u].clone() }
@@ -764,7 +765,7 @@ fn dump_output(config: &config, testfile: &Path, out: &str, err: &str) {
764765
fn dump_output_file(config: &config, testfile: &Path,
765766
out: &str, extension: &str) {
766767
let outfile = make_out_name(config, testfile, extension);
767-
file::create(&outfile).write(out.as_bytes());
768+
File::create(&outfile).write(out.as_bytes());
768769
}
769770

770771
fn make_out_name(config: &config, testfile: &Path, extension: &str) -> Path {
@@ -1015,7 +1016,7 @@ fn disassemble_extract(config: &config, _props: &TestProps,
10151016

10161017

10171018
fn count_extracted_lines(p: &Path) -> uint {
1018-
let x = file::open(&p.with_extension("ll")).read_to_end();
1019+
let x = File::open(&p.with_extension("ll")).read_to_end();
10191020
let x = str::from_utf8_owned(x);
10201021
x.line_iter().len()
10211022
}

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/terminfo/searcher.rs

+2-2
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;
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> {
@@ -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 file::open(x) 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

+4-4
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;
34+
use std::rt::io::File;
3535
use std::task;
3636
use std::to_str::ToStr;
3737
use std::f64;
@@ -353,7 +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) => Some(@mut file::create(path) as @mut io::Writer),
356+
Some(ref path) => Some(@mut File::create(path) as @mut io::Writer),
357357
None => None
358358
};
359359
let out = @mut io::stdio::stdout() as @mut io::Writer;
@@ -936,14 +936,14 @@ impl MetricMap {
936936
/// Load MetricDiff from a file.
937937
pub fn load(p: &Path) -> MetricMap {
938938
assert!(p.exists());
939-
let f = @mut file::open(p) as @mut io::Reader;
939+
let f = @mut File::open(p) as @mut io::Reader;
940940
let mut decoder = json::Decoder(json::from_reader(f).unwrap());
941941
MetricMap(Decodable::decode(&mut decoder))
942942
}
943943
944944
/// Write MetricDiff to a file.
945945
pub fn save(&self, p: &Path) {
946-
self.to_json().to_pretty_writer(@mut file::create(p) as @mut io::Writer);
946+
self.to_json().to_pretty_writer(@mut File::create(p) as @mut io::Writer);
947947
}
948948
949949
/// Compare against another MetricMap. Optionally compare all

src/libextra/workcache.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +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;
22+
use std::rt::io::File;
2323
use std::rt::io::Decorator;
2424
use std::rt::io::mem::MemWriter;
2525

@@ -176,14 +176,14 @@ impl Database {
176176

177177
// FIXME #4330: This should have &mut self and should set self.db_dirty to false.
178178
fn save(&self) {
179-
let f = @mut file::create(&self.db_filename);
179+
let f = @mut File::create(&self.db_filename);
180180
self.db_cache.to_json().to_pretty_writer(f as @mut io::Writer);
181181
}
182182

183183
fn load(&mut self) {
184184
assert!(!self.db_dirty);
185185
assert!(self.db_filename.exists());
186-
match io::result(|| file::open(&self.db_filename)) {
186+
match io::result(|| File::open(&self.db_filename)) {
187187
Err(e) => fail!("Couldn't load workcache database {}: {}",
188188
self.db_filename.display(),
189189
e.desc),
@@ -480,21 +480,20 @@ impl<'self, T:Send +
480480
#[test]
481481
fn test() {
482482
use std::{os, run};
483-
use std::rt::io::file;
484483
use std::str::from_utf8_owned;
485484

486485
// Create a path to a new file 'filename' in the directory in which
487486
// this test is running.
488487
fn make_path(filename: ~str) -> Path {
489488
let pth = os::self_exe_path().expect("workcache::test failed").with_filename(filename);
490489
if pth.exists() {
491-
file::unlink(&pth);
490+
File::unlink(&pth);
492491
}
493492
return pth;
494493
}
495494

496495
let pth = make_path(~"foo.c");
497-
file::create(&pth).write(bytes!("int main() { return 0; }"));
496+
File::create(&pth).write(bytes!("int main() { return 0; }"));
498497

499498
let db_path = make_path(~"db.json");
500499

@@ -507,7 +506,7 @@ fn test() {
507506
let subcx = cx.clone();
508507
let pth = pth.clone();
509508

510-
let file_content = from_utf8_owned(file::open(&pth).read_to_end());
509+
let file_content = from_utf8_owned(File::open(&pth).read_to_end());
511510

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

src/librustc/back/link.rs

+3-4
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::File;
3535
use syntax::ast;
3636
use syntax::ast_map::{path, path_mod, path_name, path_pretty_name};
3737
use syntax::attr;
@@ -950,18 +950,17 @@ 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+
File::unlink(obj_filename);
954954
}
955955
}
956956

957957
fn is_writeable(p: &Path) -> bool {
958958
use std::rt::io;
959-
use std::libc::consts::os::posix88::S_IWUSR;
960959

961960
!p.exists() ||
962961
(match io::result(|| p.stat()) {
963962
Err(*) => false,
964-
Ok(m) => (m.mode as uint) & S_IWUSR as uint == S_IWUSR as uint
963+
Ok(m) => m.perm & io::UserWrite == io::UserWrite
965964
})
966965
}
967966

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::File;
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+
File::unlink(&asm_filename);
374374
}
375375
} else {
376376
time(sess.time_passes(), "LLVM passes", (), |_|

src/librustdoc/html/render.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use std::local_data;
4242
use std::rt::io::buffered::BufferedWriter;
4343
use std::rt::io;
4444
use std::rt::io::file;
45+
use std::rt::io::File;
4546
use std::os;
4647
use std::str;
4748
use std::task;
@@ -263,7 +264,7 @@ pub fn run(mut crate: clean::Crate, dst: Path) {
263264
// Publish the search index
264265
{
265266
dst.push("search-index.js");
266-
let mut w = BufferedWriter::new(file::create(&dst).unwrap());
267+
let mut w = BufferedWriter::new(File::create(&dst).unwrap());
267268
let w = &mut w as &mut Writer;
268269
write!(w, "var searchIndex = [");
269270
for (i, item) in cache.search_index.iter().enumerate() {
@@ -313,7 +314,7 @@ pub fn run(mut crate: clean::Crate, dst: Path) {
313314
/// Writes the entire contents of a string to a destination, not attempting to
314315
/// catch any errors.
315316
fn write(dst: Path, contents: &str) {
316-
file::create(&dst).write(contents.as_bytes());
317+
File::create(&dst).write(contents.as_bytes());
317318
}
318319

319320
/// Makes a directory on the filesystem, failing the task if an error occurs and
@@ -419,7 +420,7 @@ impl<'self> SourceCollector<'self> {
419420
// If we couldn't open this file, then just returns because it
420421
// probably means that it's some standard library macro thing and we
421422
// can't have the source to it anyway.
422-
let mut r = match io::result(|| file::open(&p)) {
423+
let mut r = match io::result(|| File::open(&p)) {
423424
Ok(r) => r,
424425
// eew macro hacks
425426
Err(*) => return filename == "<std-macros>"
@@ -445,7 +446,7 @@ impl<'self> SourceCollector<'self> {
445446
}
446447
447448
cur.push(p.filename().expect("source has no filename") + bytes!(".html"));
448-
let mut w = BufferedWriter::new(file::create(&cur).unwrap());
449+
let mut w = BufferedWriter::new(File::create(&cur).unwrap());
449450

450451
let title = cur.filename_display().with_str(|s| format!("{} -- source", s));
451452
let page = layout::Page {
@@ -767,7 +768,7 @@ impl Context {
767768
///
768769
/// The rendering driver uses this closure to queue up more work.
769770
fn item(&mut self, item: clean::Item, f: &fn(&mut Context, clean::Item)) {
770-
fn render(w: file::FileWriter, cx: &mut Context, it: &clean::Item,
771+
fn render(w: io::File, cx: &mut Context, it: &clean::Item,
771772
pushname: bool) {
772773
// A little unfortunate that this is done like this, but it sure
773774
// does make formatting *a lot* nicer.
@@ -804,7 +805,7 @@ impl Context {
804805
do self.recurse(name) |this| {
805806
let item = item.take();
806807
let dst = this.dst.join("index.html");
807-
render(file::create(&dst).unwrap(), this, &item, false);
808+
render(File::create(&dst).unwrap(), this, &item, false);
808809

809810
let m = match item.inner {
810811
clean::ModuleItem(m) => m,
@@ -821,7 +822,7 @@ impl Context {
821822
// pages dedicated to them.
822823
_ if item.name.is_some() => {
823824
let dst = self.dst.join(item_path(&item));
824-
render(file::create(&dst).unwrap(), self, &item, true);
825+
render(File::create(&dst).unwrap(), self, &item, true);
825826
}
826827

827828
_ => {}

src/librustdoc/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern mod extra;
2626
use std::cell::Cell;
2727
use std::local_data;
2828
use std::rt::io;
29-
use std::rt::io::file;
29+
use std::rt::io::File;
3030
use std::rt::io::mem::MemWriter;
3131
use std::rt::io::Decorator;
3232
use std::str;
@@ -259,7 +259,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
259259
/// This input format purely deserializes the json output file. No passes are
260260
/// run over the deserialized output.
261261
fn json_input(input: &str) -> Result<Output, ~str> {
262-
let input = match file::open(&Path::new(input)) {
262+
let input = match File::open(&Path::new(input)) {
263263
Some(f) => f,
264264
None => return Err(format!("couldn't open {} for reading", input)),
265265
};
@@ -321,7 +321,7 @@ fn json_output(crate: clean::Crate, res: ~[plugins::PluginJson], dst: Path) {
321321
json.insert(~"crate", crate_json);
322322
json.insert(~"plugins", json::Object(plugins_json));
323323

324-
let mut file = file::create(&dst).unwrap();
324+
let mut file = File::create(&dst).unwrap();
325325
let output = json::Object(json).to_str();
326326
file.write(output.as_bytes());
327327
}

src/librustpkg/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use std::{os, result, run, str, task};
2828
use std::hashmap::HashSet;
2929
use std::rt::io;
3030
use std::rt::io::file;
31+
use std::rt::io::File;
3132
pub use std::path::Path;
3233

3334
use extra::workcache;
@@ -661,7 +662,7 @@ impl CtxMethods for BuildContext {
661662
for exec in subex.iter() {
662663
debug!("Copying: {} -> {}", exec.display(), sub_target_ex.display());
663664
file::mkdir_recursive(&sub_target_ex.dir_path(), io::UserRWX);
664-
file::copy(exec, &sub_target_ex);
665+
File::copy(exec, &sub_target_ex);
665666
// FIXME (#9639): This needs to handle non-utf8 paths
666667
exe_thing.discover_output("binary",
667668
sub_target_ex.as_str().unwrap(),
@@ -674,7 +675,7 @@ impl CtxMethods for BuildContext {
674675
didn't install it!", lib.display()));
675676
target_lib.set_filename(lib.filename().expect("weird target lib"));
676677
file::mkdir_recursive(&target_lib.dir_path(), io::UserRWX);
677-
file::copy(lib, &target_lib);
678+
File::copy(lib, &target_lib);
678679
debug!("3. discovering output {}", target_lib.display());
679680
exe_thing.discover_output("binary",
680681
target_lib.as_str().unwrap(),

0 commit comments

Comments
 (0)