diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-10-25 17:04:37 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-11-03 15:15:42 -0800 |
| commit | 9c1851019f1ef9511fa8731b8f1acb0796d1e97f (patch) | |
| tree | 0cd6d600bfc077e1d19722afdb042c9c016db621 /src/libextra/workcache.rs | |
| parent | 7bf58c2baaac3f7cb3c8e8d735b27ac9e7d3cd78 (diff) | |
| download | rust-9c1851019f1ef9511fa8731b8f1acb0796d1e97f.tar.gz rust-9c1851019f1ef9511fa8731b8f1acb0796d1e97f.zip | |
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
Diffstat (limited to 'src/libextra/workcache.rs')
| -rw-r--r-- | src/libextra/workcache.rs | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index 507962c0b1a..b2be4cf811b 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -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; /** * @@ -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 @@ -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) => { @@ -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"); @@ -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); |
