1
Fork 0

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
This commit is contained in:
Alex Crichton 2013-10-25 17:04:37 -07:00
parent 7bf58c2baa
commit 9c1851019f
57 changed files with 1364 additions and 1493 deletions

View file

@ -517,8 +517,8 @@ CTEST_BUILD_BASE_rpass = run-pass
CTEST_MODE_rpass = run-pass CTEST_MODE_rpass = run-pass
CTEST_RUNTOOL_rpass = $(CTEST_RUNTOOL) CTEST_RUNTOOL_rpass = $(CTEST_RUNTOOL)
CTEST_SRC_BASE_rpass-full = run-pass-full CTEST_SRC_BASE_rpass-full = run-pass-fulldeps
CTEST_BUILD_BASE_rpass-full = run-pass-full CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps
CTEST_MODE_rpass-full = run-pass CTEST_MODE_rpass-full = run-pass
CTEST_RUNTOOL_rpass-full = $(CTEST_RUNTOOL) CTEST_RUNTOOL_rpass-full = $(CTEST_RUNTOOL)
@ -673,7 +673,7 @@ PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
PRETTY_DEPS_pretty-bench = $(BENCH_TESTS) PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS) PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS)
PRETTY_DIRNAME_pretty-rpass = run-pass PRETTY_DIRNAME_pretty-rpass = run-pass
PRETTY_DIRNAME_pretty-rpass-full = run-pass-full PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps
PRETTY_DIRNAME_pretty-rfail = run-fail PRETTY_DIRNAME_pretty-rfail = run-fail
PRETTY_DIRNAME_pretty-bench = bench PRETTY_DIRNAME_pretty-bench = bench
PRETTY_DIRNAME_pretty-pretty = pretty PRETTY_DIRNAME_pretty-pretty = pretty

View file

@ -17,6 +17,7 @@ extern mod extra;
use std::os; use std::os;
use std::rt; use std::rt;
use std::rt::io::file;
use extra::getopts; use extra::getopts;
use extra::getopts::groups::{optopt, optflag, reqopt}; use extra::getopts::groups::{optopt, optflag, reqopt};
@ -247,7 +248,7 @@ pub fn make_tests(config: &config) -> ~[test::TestDescAndFn] {
debug!("making tests from {}", debug!("making tests from {}",
config.src_base.display()); config.src_base.display());
let mut tests = ~[]; let mut tests = ~[];
let dirs = os::list_dir_path(&config.src_base); let dirs = file::readdir(&config.src_base);
for file in dirs.iter() { for file in dirs.iter() {
let file = file.clone(); let file = file.clone();
debug!("inspecting file {}", file.display()); debug!("inspecting file {}", file.display());

View file

@ -8,16 +8,16 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use std::rt::io::buffered::BufferedReader;
use std::rt::io::file;
pub struct ExpectedError { line: uint, kind: ~str, msg: ~str } pub struct ExpectedError { line: uint, kind: ~str, msg: ~str }
// Load any test directives embedded in the file // Load any test directives embedded in the file
pub fn load_errors(testfile: &Path) -> ~[ExpectedError] { pub fn load_errors(testfile: &Path) -> ~[ExpectedError] {
use std::rt::io::Open;
use std::rt::io::file::FileInfo;
use std::rt::io::buffered::BufferedReader;
let mut error_patterns = ~[]; let mut error_patterns = ~[];
let mut rdr = BufferedReader::new(testfile.open_reader(Open).unwrap()); let mut rdr = BufferedReader::new(file::open(testfile).unwrap());
let mut line_num = 1u; let mut line_num = 1u;
loop { loop {
let ln = match rdr.read_line() { let ln = match rdr.read_line() {

View file

@ -103,11 +103,10 @@ pub fn is_test_ignored(config: &config, testfile: &Path) -> bool {
} }
fn iter_header(testfile: &Path, it: &fn(&str) -> bool) -> bool { fn iter_header(testfile: &Path, it: &fn(&str) -> bool) -> bool {
use std::rt::io::Open;
use std::rt::io::file::FileInfo;
use std::rt::io::buffered::BufferedReader; use std::rt::io::buffered::BufferedReader;
use std::rt::io::file;
let mut rdr = BufferedReader::new(testfile.open_reader(Open).unwrap()); let mut rdr = BufferedReader::new(file::open(testfile).unwrap());
loop { loop {
let ln = match rdr.read_line() { let ln = match rdr.read_line() {
Some(ln) => ln, None => break Some(ln) => ln, None => break

View file

@ -22,9 +22,7 @@ use util::logv;
use std::cell::Cell; use std::cell::Cell;
use std::rt::io; use std::rt::io;
use std::rt::io::Writer; use std::rt::io::file;
use std::rt::io::Reader;
use std::rt::io::file::FileInfo;
use std::os; use std::os;
use std::str; use std::str;
use std::task::{spawn_sched, SingleThreaded}; use std::task::{spawn_sched, SingleThreaded};
@ -173,7 +171,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
let rounds = let rounds =
match props.pp_exact { Some(_) => 1, None => 2 }; match props.pp_exact { Some(_) => 1, None => 2 };
let src = testfile.open_reader(io::Open).read_to_end(); let src = file::open(testfile).read_to_end();
let src = str::from_utf8_owned(src); let src = str::from_utf8_owned(src);
let mut srcs = ~[src]; let mut srcs = ~[src];
@ -195,7 +193,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
let mut expected = match props.pp_exact { let mut expected = match props.pp_exact {
Some(ref file) => { Some(ref file) => {
let filepath = testfile.dir_path().join(file); let filepath = testfile.dir_path().join(file);
let s = filepath.open_reader(io::Open).read_to_end(); let s = file::open(&filepath).read_to_end();
str::from_utf8_owned(s) str::from_utf8_owned(s)
} }
None => { srcs[srcs.len() - 2u].clone() } None => { srcs[srcs.len() - 2u].clone() }
@ -651,10 +649,8 @@ fn compose_and_run_compiler(
} }
fn ensure_dir(path: &Path) { fn ensure_dir(path: &Path) {
if os::path_is_dir(path) { return; } if path.is_dir() { return; }
if !os::make_dir(path, 0x1c0i32) { file::mkdir(path, io::UserRWX);
fail!("can't make dir {}", path.display());
}
} }
fn compose_and_run(config: &config, testfile: &Path, fn compose_and_run(config: &config, testfile: &Path,
@ -768,7 +764,7 @@ fn dump_output(config: &config, testfile: &Path, out: &str, err: &str) {
fn dump_output_file(config: &config, testfile: &Path, fn dump_output_file(config: &config, testfile: &Path,
out: &str, extension: &str) { out: &str, extension: &str) {
let outfile = make_out_name(config, testfile, extension); let outfile = make_out_name(config, testfile, extension);
outfile.open_writer(io::CreateOrTruncate).write(out.as_bytes()); file::create(&outfile).write(out.as_bytes());
} }
fn make_out_name(config: &config, testfile: &Path, extension: &str) -> Path { fn make_out_name(config: &config, testfile: &Path, extension: &str) -> Path {
@ -924,7 +920,7 @@ fn _dummy_exec_compiled_test(config: &config, props: &TestProps,
fn _arm_push_aux_shared_library(config: &config, testfile: &Path) { fn _arm_push_aux_shared_library(config: &config, testfile: &Path) {
let tdir = aux_output_dir_name(config, testfile); let tdir = aux_output_dir_name(config, testfile);
let dirs = os::list_dir_path(&tdir); let dirs = file::readdir(&tdir);
for file in dirs.iter() { for file in dirs.iter() {
if file.extension_str() == Some("so") { if file.extension_str() == Some("so") {
// FIXME (#9639): This needs to handle non-utf8 paths // FIXME (#9639): This needs to handle non-utf8 paths
@ -1019,7 +1015,7 @@ fn disassemble_extract(config: &config, _props: &TestProps,
fn count_extracted_lines(p: &Path) -> uint { fn count_extracted_lines(p: &Path) -> uint {
let x = p.with_extension("ll").open_reader(io::Open).read_to_end(); let x = file::open(&p.with_extension("ll")).read_to_end();
let x = str::from_utf8_owned(x); let x = str::from_utf8_owned(x);
x.line_iter().len() x.line_iter().len()
} }

View file

@ -24,6 +24,8 @@
*/ */
use std::{os, path}; use std::{os, path};
use std::rt::io;
use std::rt::io::file;
use std::path::is_sep; use std::path::is_sep;
use sort; use sort;
@ -146,9 +148,14 @@ impl Iterator<Path> for GlobIterator {
} }
fn list_dir_sorted(path: &Path) -> ~[Path] { fn list_dir_sorted(path: &Path) -> ~[Path] {
let mut children = os::list_dir_path(path); match io::result(|| file::readdir(path)) {
sort::quick_sort(children, |p1, p2| p2.filename().unwrap() <= p1.filename().unwrap()); Ok(children) => {
children let mut children = children;
sort::quick_sort(children, |p1, p2| p2.filename() <= p1.filename());
children
}
Err(*) => ~[]
}
} }
/** /**

View file

@ -14,6 +14,8 @@
use std::os; use std::os;
use std::rand::Rng; use std::rand::Rng;
use std::rand; use std::rand;
use std::rt::io;
use std::rt::io::file;
/// A wrapper for a path to temporary directory implementing automatic /// A wrapper for a path to temporary directory implementing automatic
/// scope-pased deletion. /// scope-pased deletion.
@ -36,8 +38,9 @@ impl TempDir {
let mut r = rand::rng(); let mut r = rand::rng();
for _ in range(0u, 1000) { for _ in range(0u, 1000) {
let p = tmpdir.join(r.gen_ascii_str(16) + suffix); let p = tmpdir.join(r.gen_ascii_str(16) + suffix);
if os::make_dir(&p, 0x1c0) { // 700 match io::result(|| file::mkdir(&p, io::UserRWX)) {
return Some(TempDir { path: Some(p) }); Err(*) => {}
Ok(()) => return Some(TempDir { path: Some(p) })
} }
} }
None None
@ -69,7 +72,9 @@ impl TempDir {
impl Drop for TempDir { impl Drop for TempDir {
fn drop(&mut self) { fn drop(&mut self) {
for path in self.path.iter() { for path in self.path.iter() {
os::remove_dir_recursive(path); if path.exists() {
file::rmdir_recursive(path);
}
} }
} }
} }

View file

@ -14,7 +14,7 @@
use std::{os, str}; use std::{os, str};
use std::os::getenv; use std::os::getenv;
use std::rt::io; use std::rt::io;
use std::rt::io::file::FileInfo; use std::rt::io::file;
/// Return path to database entry for `term` /// Return path to database entry for `term`
pub fn get_dbpath_for_term(term: &str) -> Option<~Path> { pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
@ -56,16 +56,16 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
// Look for the terminal in all of the search directories // Look for the terminal in all of the search directories
for p in dirs_to_search.iter() { for p in dirs_to_search.iter() {
if os::path_exists(p) { if p.exists() {
let f = str::from_char(first_char); let f = str::from_char(first_char);
let newp = p.join_many([f.as_slice(), term]); let newp = p.join_many([f.as_slice(), term]);
if os::path_exists(&newp) { if newp.exists() {
return Some(~newp); return Some(~newp);
} }
// on some installations the dir is named after the hex of the char (e.g. OS X) // on some installations the dir is named after the hex of the char (e.g. OS X)
let f = format!("{:x}", first_char as uint); let f = format!("{:x}", first_char as uint);
let newp = p.join_many([f.as_slice(), term]); let newp = p.join_many([f.as_slice(), term]);
if os::path_exists(&newp) { if newp.exists() {
return Some(~newp); return Some(~newp);
} }
} }
@ -76,7 +76,7 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
/// Return open file for `term` /// Return open file for `term`
pub fn open(term: &str) -> Result<@mut io::Reader, ~str> { pub fn open(term: &str) -> Result<@mut io::Reader, ~str> {
match get_dbpath_for_term(term) { match get_dbpath_for_term(term) {
Some(x) => Ok(@mut x.open_reader(io::Open).unwrap() as @mut io::Reader), Some(x) => Ok(@mut file::open(x) as @mut io::Reader),
None => Err(format!("could not find terminfo entry for {}", term)) None => Err(format!("could not find terminfo entry for {}", term))
} }
} }

View file

@ -31,7 +31,7 @@ use treemap::TreeMap;
use std::clone::Clone; use std::clone::Clone;
use std::comm::{stream, SharedChan, GenericPort, GenericChan}; use std::comm::{stream, SharedChan, GenericPort, GenericChan};
use std::rt::io; use std::rt::io;
use std::rt::io::file::FileInfo; use std::rt::io::file;
use std::task; use std::task;
use std::to_str::ToStr; use std::to_str::ToStr;
use std::f64; use std::f64;
@ -353,10 +353,7 @@ struct ConsoleTestState {
impl ConsoleTestState { impl ConsoleTestState {
pub fn new(opts: &TestOpts) -> ConsoleTestState { pub fn new(opts: &TestOpts) -> ConsoleTestState {
let log_out = match opts.logfile { let log_out = match opts.logfile {
Some(ref path) => { Some(ref path) => Some(@mut file::create(path) as @mut io::Writer),
let out = path.open_writer(io::CreateOrTruncate);
Some(@mut out as @mut io::Writer)
},
None => None None => None
}; };
let out = @mut io::stdio::stdout() as @mut io::Writer; let out = @mut io::stdio::stdout() as @mut io::Writer;
@ -938,16 +935,15 @@ impl MetricMap {
/// Load MetricDiff from a file. /// Load MetricDiff from a file.
pub fn load(p: &Path) -> MetricMap { pub fn load(p: &Path) -> MetricMap {
assert!(os::path_exists(p)); assert!(p.exists());
let f = @mut p.open_reader(io::Open) as @mut io::Reader; let f = @mut file::open(p) as @mut io::Reader;
let mut decoder = json::Decoder(json::from_reader(f).unwrap()); let mut decoder = json::Decoder(json::from_reader(f).unwrap());
MetricMap(Decodable::decode(&mut decoder)) MetricMap(Decodable::decode(&mut decoder))
} }
/// Write MetricDiff to a file. /// Write MetricDiff to a file.
pub fn save(&self, p: &Path) { pub fn save(&self, p: &Path) {
let f = @mut p.open_writer(io::CreateOrTruncate); self.to_json().to_pretty_writer(@mut file::create(p) as @mut io::Writer);
self.to_json().to_pretty_writer(f as @mut io::Writer);
} }
/// Compare against another MetricMap. Optionally compare all /// Compare against another MetricMap. Optionally compare all
@ -1032,7 +1028,7 @@ impl MetricMap {
/// `MetricChange`s are `Regression`. Returns the diff as well /// `MetricChange`s are `Regression`. Returns the diff as well
/// as a boolean indicating whether the ratchet succeeded. /// as a boolean indicating whether the ratchet succeeded.
pub fn ratchet(&self, p: &Path, pct: Option<f64>) -> (MetricDiff, bool) { pub fn ratchet(&self, p: &Path, pct: Option<f64>) -> (MetricDiff, bool) {
let old = if os::path_exists(p) { let old = if p.exists() {
MetricMap::load(p) MetricMap::load(p)
} else { } else {
MetricMap::new() MetricMap::new()

View file

@ -792,7 +792,6 @@ mod test {
#[test] #[test]
fn test_serialize_round_trip() { fn test_serialize_round_trip() {
use std;
use ebml; use ebml;
use serialize::{Encodable, Decodable}; use serialize::{Encodable, Decodable};

View file

@ -17,13 +17,11 @@ use arc::{Arc,RWArc};
use treemap::TreeMap; use treemap::TreeMap;
use std::cell::Cell; use std::cell::Cell;
use std::comm::{PortOne, oneshot}; use std::comm::{PortOne, oneshot};
use std::{os, str, task}; use std::{str, task};
use std::rt::io; use std::rt::io;
use std::rt::io::Writer; use std::rt::io::file;
use std::rt::io::Reader;
use std::rt::io::Decorator; use std::rt::io::Decorator;
use std::rt::io::mem::MemWriter; use std::rt::io::mem::MemWriter;
use std::rt::io::file::FileInfo;
/** /**
* *
@ -145,7 +143,7 @@ impl Database {
db_cache: TreeMap::new(), db_cache: TreeMap::new(),
db_dirty: false db_dirty: false
}; };
if os::path_exists(&rslt.db_filename) { if rslt.db_filename.exists() {
rslt.load(); rslt.load();
} }
rslt rslt
@ -178,19 +176,19 @@ impl Database {
// FIXME #4330: This should have &mut self and should set self.db_dirty to false. // FIXME #4330: This should have &mut self and should set self.db_dirty to false.
fn save(&self) { 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); self.db_cache.to_json().to_pretty_writer(f as @mut io::Writer);
} }
fn load(&mut self) { fn load(&mut self) {
assert!(!self.db_dirty); assert!(!self.db_dirty);
assert!(os::path_exists(&self.db_filename)); assert!(self.db_filename.exists());
let f = self.db_filename.open_reader(io::Open); match io::result(|| file::open(&self.db_filename)) {
match f { Err(e) => fail!("Couldn't load workcache database {}: {}",
None => fail!("Couldn't load workcache database {}", self.db_filename.display(),
self.db_filename.display()), e.desc),
Some(r) => Ok(r) =>
match json::from_reader(@mut r as @mut io::Reader) { match json::from_reader(@mut r.unwrap() as @mut io::Reader) {
Err(e) => fail!("Couldn't parse workcache database (from file {}): {}", Err(e) => fail!("Couldn't parse workcache database (from file {}): {}",
self.db_filename.display(), e.to_str()), self.db_filename.display(), e.to_str()),
Ok(r) => { Ok(r) => {
@ -482,23 +480,21 @@ impl<'self, T:Send +
#[test] #[test]
fn test() { fn test() {
use std::{os, run}; use std::{os, run};
use std::rt::io::Reader; use std::rt::io::file;
use std::str::from_utf8_owned; use std::str::from_utf8_owned;
// Create a path to a new file 'filename' in the directory in which // Create a path to a new file 'filename' in the directory in which
// this test is running. // this test is running.
fn make_path(filename: ~str) -> Path { fn make_path(filename: ~str) -> Path {
let pth = os::self_exe_path().expect("workcache::test failed").with_filename(filename); let pth = os::self_exe_path().expect("workcache::test failed").with_filename(filename);
if os::path_exists(&pth) { if pth.exists() {
os::remove_file(&pth); file::unlink(&pth);
} }
return pth; return pth;
} }
let pth = make_path(~"foo.c"); let pth = make_path(~"foo.c");
{ file::create(&pth).write(bytes!("int main() { return 0; }"));
pth.open_writer(io::Create).write(bytes!("int main() { return 0; }"));
}
let db_path = make_path(~"db.json"); let db_path = make_path(~"db.json");
@ -511,7 +507,7 @@ fn test() {
let subcx = cx.clone(); let subcx = cx.clone();
let pth = pth.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 // FIXME (#9639): This needs to handle non-utf8 paths
prep.declare_input("file", pth.as_str().unwrap(), file_content); prep.declare_input("file", pth.as_str().unwrap(), file_content);

View file

@ -27,12 +27,11 @@ use std::char;
use std::hash::Streaming; use std::hash::Streaming;
use std::hash; use std::hash;
use std::os::consts::{macos, freebsd, linux, android, win32}; use std::os::consts::{macos, freebsd, linux, android, win32};
use std::os;
use std::ptr; use std::ptr;
use std::rt::io::Writer;
use std::run; use std::run;
use std::str; use std::str;
use std::vec; use std::vec;
use std::rt::io::file;
use syntax::ast; use syntax::ast;
use syntax::ast_map::{path, path_mod, path_name, path_pretty_name}; use syntax::ast_map::{path, path_mod, path_name, path_pretty_name};
use syntax::attr; use syntax::attr;
@ -951,20 +950,18 @@ pub fn link_binary(sess: Session,
// Remove the temporary object file if we aren't saving temps // Remove the temporary object file if we aren't saving temps
if !sess.opts.save_temps { if !sess.opts.save_temps {
if ! os::remove_file(obj_filename) { file::unlink(obj_filename);
sess.warn(format!("failed to delete object file `{}`",
obj_filename.display()));
}
} }
} }
fn is_writeable(p: &Path) -> bool { fn is_writeable(p: &Path) -> bool {
use std::rt::io;
use std::libc::consts::os::posix88::S_IWUSR; use std::libc::consts::os::posix88::S_IWUSR;
!os::path_exists(p) || !p.exists() ||
(match p.get_mode() { (match io::result(|| p.stat()) {
None => false, Err(*) => false,
Some(m) => m & S_IWUSR as uint == S_IWUSR as uint Ok(m) => (m.mode as uint) & S_IWUSR as uint == S_IWUSR as uint
}) })
} }

View file

@ -27,6 +27,7 @@ use util::ppaux;
use std::hashmap::{HashMap,HashSet}; use std::hashmap::{HashMap,HashSet};
use std::rt::io; use std::rt::io;
use std::rt::io::file;
use std::rt::io::mem::MemReader; use std::rt::io::mem::MemReader;
use std::os; use std::os;
use std::vec; use std::vec;
@ -369,7 +370,7 @@ pub fn phase_5_run_llvm_passes(sess: Session,
// Remove assembly source unless --save-temps was specified // Remove assembly source unless --save-temps was specified
if !sess.opts.save_temps { if !sess.opts.save_temps {
os::remove_file(&asm_filename); file::unlink(&asm_filename);
} }
} else { } else {
time(sess.time_passes(), "LLVM passes", (), |_| time(sess.time_passes(), "LLVM passes", (), |_|

View file

@ -11,6 +11,8 @@
use std::option; use std::option;
use std::os; use std::os;
use std::rt::io;
use std::rt::io::file;
use std::hashmap::HashSet; use std::hashmap::HashSet;
pub enum FileMatch { FileMatches, FileDoesntMatch } pub enum FileMatch { FileMatches, FileDoesntMatch }
@ -117,22 +119,26 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
pub fn search(filesearch: @FileSearch, pick: pick) { pub fn search(filesearch: @FileSearch, pick: pick) {
do filesearch.for_each_lib_search_path() |lib_search_path| { do filesearch.for_each_lib_search_path() |lib_search_path| {
debug!("searching {}", lib_search_path.display()); debug!("searching {}", lib_search_path.display());
let r = os::list_dir_path(lib_search_path); match io::result(|| file::readdir(lib_search_path)) {
let mut rslt = FileDoesntMatch; Ok(files) => {
for path in r.iter() { let mut rslt = FileDoesntMatch;
debug!("testing {}", path.display()); for path in files.iter() {
let maybe_picked = pick(path); debug!("testing {}", path.display());
match maybe_picked { let maybe_picked = pick(path);
FileMatches => { match maybe_picked {
debug!("picked {}", path.display()); FileMatches => {
rslt = FileMatches; debug!("picked {}", path.display());
} rslt = FileMatches;
FileDoesntMatch => { }
debug!("rejected {}", path.display()); FileDoesntMatch => {
debug!("rejected {}", path.display());
}
}
} }
rslt
} }
Err(*) => FileDoesntMatch,
} }
rslt
}; };
} }
@ -210,7 +216,7 @@ pub fn rust_path() -> ~[Path] {
break break
} }
cwd.set_filename(".rust"); cwd.set_filename(".rust");
if !env_rust_path.contains(&cwd) && os::path_exists(&cwd) { if !env_rust_path.contains(&cwd) && cwd.exists() {
env_rust_path.push(cwd.clone()); env_rust_path.push(cwd.clone());
} }
cwd.pop(); cwd.pop();
@ -218,7 +224,7 @@ pub fn rust_path() -> ~[Path] {
let h = os::homedir(); let h = os::homedir();
for h in h.iter() { for h in h.iter() {
let p = h.join(".rust"); let p = h.join(".rust");
if !env_rust_path.contains(&p) && os::path_exists(&p) { if !env_rust_path.contains(&p) && p.exists() {
env_rust_path.push(p); env_rust_path.push(p);
} }
} }

View file

@ -40,10 +40,8 @@ use std::fmt;
use std::hashmap::{HashMap, HashSet}; use std::hashmap::{HashMap, HashSet};
use std::local_data; use std::local_data;
use std::rt::io::buffered::BufferedWriter; use std::rt::io::buffered::BufferedWriter;
use std::rt::io::file::{FileInfo, DirectoryInfo};
use std::rt::io::file;
use std::rt::io; use std::rt::io;
use std::rt::io::Reader; use std::rt::io::file;
use std::os; use std::os;
use std::str; use std::str;
use std::task; use std::task;
@ -265,8 +263,8 @@ pub fn run(mut crate: clean::Crate, dst: Path) {
// Publish the search index // Publish the search index
{ {
dst.push("search-index.js"); dst.push("search-index.js");
let mut w = BufferedWriter::new(dst.open_writer(io::CreateOrTruncate)); let mut w = BufferedWriter::new(file::create(&dst).unwrap());
let w = &mut w as &mut io::Writer; let w = &mut w as &mut Writer;
write!(w, "var searchIndex = ["); write!(w, "var searchIndex = [");
for (i, item) in cache.search_index.iter().enumerate() { for (i, item) in cache.search_index.iter().enumerate() {
if i > 0 { write!(w, ","); } if i > 0 { write!(w, ","); }
@ -315,8 +313,7 @@ pub fn run(mut crate: clean::Crate, dst: Path) {
/// Writes the entire contents of a string to a destination, not attempting to /// Writes the entire contents of a string to a destination, not attempting to
/// catch any errors. /// catch any errors.
fn write(dst: Path, contents: &str) { fn write(dst: Path, contents: &str) {
let mut w = dst.open_writer(io::CreateOrTruncate); file::create(&dst).write(contents.as_bytes());
w.write(contents.as_bytes());
} }
/// Makes a directory on the filesystem, failing the task if an error occurs and /// Makes a directory on the filesystem, failing the task if an error occurs and
@ -328,7 +325,7 @@ fn mkdir(path: &Path) {
fail!() fail!()
}).inside { }).inside {
if !path.is_dir() { if !path.is_dir() {
file::mkdir(path); file::mkdir(path, io::UserRWX);
} }
} }
} }
@ -419,16 +416,13 @@ impl<'self> SourceCollector<'self> {
let mut contents = ~[]; let mut contents = ~[];
{ {
let mut buf = [0, ..1024]; let mut buf = [0, ..1024];
let r = do io::io_error::cond.trap(|_| {}).inside {
p.open_reader(io::Open)
};
// If we couldn't open this file, then just returns because it // If we couldn't open this file, then just returns because it
// probably means that it's some standard library macro thing and we // probably means that it's some standard library macro thing and we
// can't have the source to it anyway. // can't have the source to it anyway.
let mut r = match r { let mut r = match io::result(|| file::open(&p)) {
Some(r) => r, Ok(r) => r,
// eew macro hacks // eew macro hacks
None => return filename == "<std-macros>" Err(*) => return filename == "<std-macros>"
}; };
// read everything // read everything
@ -451,8 +445,7 @@ impl<'self> SourceCollector<'self> {
} }
cur.push(p.filename().expect("source has no filename") + bytes!(".html")); cur.push(p.filename().expect("source has no filename") + bytes!(".html"));
let w = cur.open_writer(io::CreateOrTruncate); let mut w = BufferedWriter::new(file::create(&cur).unwrap());
let mut w = BufferedWriter::new(w);
let title = cur.filename_display().with_str(|s| format!("{} -- source", s)); let title = cur.filename_display().with_str(|s| format!("{} -- source", s));
let page = layout::Page { let page = layout::Page {
@ -460,7 +453,7 @@ impl<'self> SourceCollector<'self> {
ty: "source", ty: "source",
root_path: root_path, root_path: root_path,
}; };
layout::render(&mut w as &mut io::Writer, &self.cx.layout, layout::render(&mut w as &mut Writer, &self.cx.layout,
&page, &(""), &Source(contents.as_slice())); &page, &(""), &Source(contents.as_slice()));
w.flush(); w.flush();
return true; return true;
@ -774,7 +767,7 @@ impl Context {
/// ///
/// The rendering driver uses this closure to queue up more work. /// The rendering driver uses this closure to queue up more work.
fn item(&mut self, item: clean::Item, f: &fn(&mut Context, clean::Item)) { fn item(&mut self, item: clean::Item, f: &fn(&mut Context, clean::Item)) {
fn render(w: io::file::FileWriter, cx: &mut Context, it: &clean::Item, fn render(w: file::FileWriter, cx: &mut Context, it: &clean::Item,
pushname: bool) { pushname: bool) {
// A little unfortunate that this is done like this, but it sure // A little unfortunate that this is done like this, but it sure
// does make formatting *a lot* nicer. // does make formatting *a lot* nicer.
@ -796,7 +789,7 @@ impl Context {
// of the pain by using a buffered writer instead of invoking the // of the pain by using a buffered writer instead of invoking the
// write sycall all the time. // write sycall all the time.
let mut writer = BufferedWriter::new(w); let mut writer = BufferedWriter::new(w);
layout::render(&mut writer as &mut io::Writer, &cx.layout, &page, layout::render(&mut writer as &mut Writer, &cx.layout, &page,
&Sidebar{ cx: cx, item: it }, &Sidebar{ cx: cx, item: it },
&Item{ cx: cx, item: it }); &Item{ cx: cx, item: it });
writer.flush(); writer.flush();
@ -811,8 +804,7 @@ impl Context {
do self.recurse(name) |this| { do self.recurse(name) |this| {
let item = item.take(); let item = item.take();
let dst = this.dst.join("index.html"); let dst = this.dst.join("index.html");
let writer = dst.open_writer(io::CreateOrTruncate); render(file::create(&dst).unwrap(), this, &item, false);
render(writer.unwrap(), this, &item, false);
let m = match item.inner { let m = match item.inner {
clean::ModuleItem(m) => m, clean::ModuleItem(m) => m,
@ -829,8 +821,7 @@ impl Context {
// pages dedicated to them. // pages dedicated to them.
_ if item.name.is_some() => { _ if item.name.is_some() => {
let dst = self.dst.join(item_path(&item)); let dst = self.dst.join(item_path(&item));
let writer = dst.open_writer(io::CreateOrTruncate); render(file::create(&dst).unwrap(), self, &item, true);
render(writer.unwrap(), self, &item, true);
} }
_ => {} _ => {}
@ -967,7 +958,7 @@ fn shorter<'a>(s: Option<&'a str>) -> &'a str {
} }
} }
fn document(w: &mut io::Writer, item: &clean::Item) { fn document(w: &mut Writer, item: &clean::Item) {
match item.doc_value() { match item.doc_value() {
Some(s) => { Some(s) => {
write!(w, "<div class='docblock'>{}</div>", Markdown(s)); write!(w, "<div class='docblock'>{}</div>", Markdown(s));
@ -976,7 +967,7 @@ fn document(w: &mut io::Writer, item: &clean::Item) {
} }
} }
fn item_module(w: &mut io::Writer, cx: &Context, fn item_module(w: &mut Writer, cx: &Context,
item: &clean::Item, items: &[clean::Item]) { item: &clean::Item, items: &[clean::Item]) {
document(w, item); document(w, item);
debug!("{:?}", items); debug!("{:?}", items);
@ -1123,7 +1114,7 @@ fn item_module(w: &mut io::Writer, cx: &Context,
write!(w, "</table>"); write!(w, "</table>");
} }
fn item_function(w: &mut io::Writer, it: &clean::Item, f: &clean::Function) { fn item_function(w: &mut Writer, it: &clean::Item, f: &clean::Function) {
write!(w, "<pre class='fn'>{vis}{purity}fn {name}{generics}{decl}</pre>", write!(w, "<pre class='fn'>{vis}{purity}fn {name}{generics}{decl}</pre>",
vis = VisSpace(it.visibility), vis = VisSpace(it.visibility),
purity = PuritySpace(f.purity), purity = PuritySpace(f.purity),
@ -1133,7 +1124,7 @@ fn item_function(w: &mut io::Writer, it: &clean::Item, f: &clean::Function) {
document(w, it); document(w, it);
} }
fn item_trait(w: &mut io::Writer, it: &clean::Item, t: &clean::Trait) { fn item_trait(w: &mut Writer, it: &clean::Item, t: &clean::Trait) {
let mut parents = ~""; let mut parents = ~"";
if t.parents.len() > 0 { if t.parents.len() > 0 {
parents.push_str(": "); parents.push_str(": ");
@ -1176,7 +1167,7 @@ fn item_trait(w: &mut io::Writer, it: &clean::Item, t: &clean::Trait) {
// Trait documentation // Trait documentation
document(w, it); document(w, it);
fn meth(w: &mut io::Writer, m: &clean::TraitMethod) { fn meth(w: &mut Writer, m: &clean::TraitMethod) {
write!(w, "<h3 id='{}.{}' class='method'><code>", write!(w, "<h3 id='{}.{}' class='method'><code>",
shortty(m.item()), shortty(m.item()),
*m.item().name.get_ref()); *m.item().name.get_ref());
@ -1234,8 +1225,8 @@ fn item_trait(w: &mut io::Writer, it: &clean::Item, t: &clean::Trait) {
} }
} }
fn render_method(w: &mut io::Writer, meth: &clean::Item, withlink: bool) { fn render_method(w: &mut Writer, meth: &clean::Item, withlink: bool) {
fn fun(w: &mut io::Writer, it: &clean::Item, purity: ast::purity, fn fun(w: &mut Writer, it: &clean::Item, purity: ast::purity,
g: &clean::Generics, selfty: &clean::SelfTy, d: &clean::FnDecl, g: &clean::Generics, selfty: &clean::SelfTy, d: &clean::FnDecl,
withlink: bool) { withlink: bool) {
write!(w, "{}fn {withlink, select, write!(w, "{}fn {withlink, select,
@ -1264,7 +1255,7 @@ fn render_method(w: &mut io::Writer, meth: &clean::Item, withlink: bool) {
} }
} }
fn item_struct(w: &mut io::Writer, it: &clean::Item, s: &clean::Struct) { fn item_struct(w: &mut Writer, it: &clean::Item, s: &clean::Struct) {
write!(w, "<pre class='struct'>"); write!(w, "<pre class='struct'>");
render_struct(w, it, Some(&s.generics), s.struct_type, s.fields, render_struct(w, it, Some(&s.generics), s.struct_type, s.fields,
s.fields_stripped, "", true); s.fields_stripped, "", true);
@ -1288,7 +1279,7 @@ fn item_struct(w: &mut io::Writer, it: &clean::Item, s: &clean::Struct) {
render_methods(w, it); render_methods(w, it);
} }
fn item_enum(w: &mut io::Writer, it: &clean::Item, e: &clean::Enum) { fn item_enum(w: &mut Writer, it: &clean::Item, e: &clean::Enum) {
write!(w, "<pre class='enum'>{}enum {}{}", write!(w, "<pre class='enum'>{}enum {}{}",
VisSpace(it.visibility), VisSpace(it.visibility),
it.name.get_ref().as_slice(), it.name.get_ref().as_slice(),
@ -1365,7 +1356,7 @@ fn item_enum(w: &mut io::Writer, it: &clean::Item, e: &clean::Enum) {
render_methods(w, it); render_methods(w, it);
} }
fn render_struct(w: &mut io::Writer, it: &clean::Item, fn render_struct(w: &mut Writer, it: &clean::Item,
g: Option<&clean::Generics>, g: Option<&clean::Generics>,
ty: doctree::StructType, ty: doctree::StructType,
fields: &[clean::Item], fields: &[clean::Item],
@ -1418,7 +1409,7 @@ fn render_struct(w: &mut io::Writer, it: &clean::Item,
} }
} }
fn render_methods(w: &mut io::Writer, it: &clean::Item) { fn render_methods(w: &mut Writer, it: &clean::Item) {
do local_data::get(cache_key) |cache| { do local_data::get(cache_key) |cache| {
let cache = cache.unwrap(); let cache = cache.unwrap();
do cache.read |c| { do cache.read |c| {
@ -1453,7 +1444,7 @@ fn render_methods(w: &mut io::Writer, it: &clean::Item) {
} }
} }
fn render_impl(w: &mut io::Writer, i: &clean::Impl, dox: &Option<~str>) { fn render_impl(w: &mut Writer, i: &clean::Impl, dox: &Option<~str>) {
write!(w, "<h3 class='impl'><code>impl{} ", i.generics); write!(w, "<h3 class='impl'><code>impl{} ", i.generics);
let trait_id = match i.trait_ { let trait_id = match i.trait_ {
Some(ref ty) => { Some(ref ty) => {
@ -1474,7 +1465,7 @@ fn render_impl(w: &mut io::Writer, i: &clean::Impl, dox: &Option<~str>) {
None => {} None => {}
} }
fn docmeth(w: &mut io::Writer, item: &clean::Item) -> bool { fn docmeth(w: &mut Writer, item: &clean::Item) -> bool {
write!(w, "<h4 id='method.{}' class='method'><code>", write!(w, "<h4 id='method.{}' class='method'><code>",
*item.name.get_ref()); *item.name.get_ref());
render_method(w, item, false); render_method(w, item, false);
@ -1552,7 +1543,7 @@ fn render_impl(w: &mut io::Writer, i: &clean::Impl, dox: &Option<~str>) {
write!(w, "</div>"); write!(w, "</div>");
} }
fn item_typedef(w: &mut io::Writer, it: &clean::Item, t: &clean::Typedef) { fn item_typedef(w: &mut Writer, it: &clean::Item, t: &clean::Typedef) {
write!(w, "<pre class='typedef'>type {}{} = {};</pre>", write!(w, "<pre class='typedef'>type {}{} = {};</pre>",
it.name.get_ref().as_slice(), it.name.get_ref().as_slice(),
t.generics, t.generics,
@ -1574,7 +1565,7 @@ impl<'self> fmt::Default for Sidebar<'self> {
} }
write!(fmt.buf, "</p>"); write!(fmt.buf, "</p>");
fn block(w: &mut io::Writer, short: &str, longty: &str, fn block(w: &mut Writer, short: &str, longty: &str,
cur: &clean::Item, cx: &Context) { cur: &clean::Item, cx: &Context) {
let items = match cx.sidebar.find_equiv(&short) { let items = match cx.sidebar.find_equiv(&short) {
Some(items) => items.as_slice(), Some(items) => items.as_slice(),

View file

@ -25,9 +25,8 @@ extern mod extra;
use std::cell::Cell; use std::cell::Cell;
use std::local_data; use std::local_data;
use std::rt::io::Writer;
use std::rt::io::file::FileInfo;
use std::rt::io; use std::rt::io;
use std::rt::io::file;
use std::rt::io::mem::MemWriter; use std::rt::io::mem::MemWriter;
use std::rt::io::Decorator; use std::rt::io::Decorator;
use std::str; use std::str;
@ -260,7 +259,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
/// This input format purely deserializes the json output file. No passes are /// This input format purely deserializes the json output file. No passes are
/// run over the deserialized output. /// run over the deserialized output.
fn json_input(input: &str) -> Result<Output, ~str> { fn json_input(input: &str) -> Result<Output, ~str> {
let input = match Path::new(input).open_reader(io::Open) { let input = match file::open(&Path::new(input)) {
Some(f) => f, Some(f) => f,
None => return Err(format!("couldn't open {} for reading", input)), None => return Err(format!("couldn't open {} for reading", input)),
}; };
@ -322,7 +321,7 @@ fn json_output(crate: clean::Crate, res: ~[plugins::PluginJson], dst: Path) {
json.insert(~"crate", crate_json); json.insert(~"crate", crate_json);
json.insert(~"plugins", json::Object(plugins_json)); json.insert(~"plugins", json::Object(plugins_json));
let mut file = dst.open_writer(io::Create).unwrap(); let mut file = file::create(&dst).unwrap();
let output = json::Object(json).to_str(); let output = json::Object(json).to_str();
file.write(output.as_bytes()); file.write(output.as_bytes());
} }

View file

@ -21,7 +21,7 @@ pub use path_util::default_workspace;
pub use source_control::{safe_git_clone, git_clone_url}; pub use source_control::{safe_git_clone, git_clone_url};
use std::{os, run}; use std::run;
use extra::arc::{Arc,RWArc}; use extra::arc::{Arc,RWArc};
use extra::workcache; use extra::workcache;
use extra::workcache::{Database, Logger, FreshnessMap}; use extra::workcache::{Database, Logger, FreshnessMap};
@ -57,12 +57,12 @@ pub fn new_default_context(c: workcache::Context, p: Path) -> BuildContext {
fn file_is_fresh(path: &str, in_hash: &str) -> bool { fn file_is_fresh(path: &str, in_hash: &str) -> bool {
let path = Path::new(path); let path = Path::new(path);
os::path_exists(&path) && in_hash == digest_file_with_date(&path) path.exists() && in_hash == digest_file_with_date(&path)
} }
fn binary_is_fresh(path: &str, in_hash: &str) -> bool { fn binary_is_fresh(path: &str, in_hash: &str) -> bool {
let path = Path::new(path); let path = Path::new(path);
os::path_exists(&path) && in_hash == digest_only_date(&path) path.exists() && in_hash == digest_only_date(&path)
} }
pub fn new_workcache_context(p: &Path) -> workcache::Context { pub fn new_workcache_context(p: &Path) -> workcache::Context {

View file

@ -14,7 +14,6 @@ use extra::workcache;
use rustc::driver::session::{OptLevel, No}; use rustc::driver::session::{OptLevel, No};
use std::hashmap::HashSet; use std::hashmap::HashSet;
use std::os;
#[deriving(Clone)] #[deriving(Clone)]
pub struct Context { pub struct Context {
@ -176,7 +175,7 @@ pub fn in_target(sysroot: &Path) -> bool {
debug!("Checking whether {} is in target", sysroot.display()); debug!("Checking whether {} is in target", sysroot.display());
let mut p = sysroot.dir_path(); let mut p = sysroot.dir_path();
p.set_filename("rustc"); p.set_filename("rustc");
os::path_is_dir(&p) p.is_dir()
} }
impl RustcFlags { impl RustcFlags {

View file

@ -13,11 +13,13 @@
use rustc::metadata::filesearch::rust_path; use rustc::metadata::filesearch::rust_path;
use path_util::*; use path_util::*;
use std::os; use std::os;
use std::rt::io;
use std::rt::io::file;
pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool { pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool {
let workspaces = rust_path(); let workspaces = rust_path();
for p in workspaces.iter() { for p in workspaces.iter() {
let binfiles = os::list_dir(&p.join("bin")); let binfiles = do io::ignore_io_error { file::readdir(&p.join("bin")) };
for exec in binfiles.iter() { for exec in binfiles.iter() {
// FIXME (#9639): This needs to handle non-utf8 paths // FIXME (#9639): This needs to handle non-utf8 paths
match exec.filestem_str() { match exec.filestem_str() {
@ -29,7 +31,7 @@ pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool {
} }
} }
} }
let libfiles = os::list_dir(&p.join("lib")); let libfiles = do io::ignore_io_error { file::readdir(&p.join("lib")) };
for lib in libfiles.iter() { for lib in libfiles.iter() {
debug!("Full name: {}", lib.display()); debug!("Full name: {}", lib.display());
match has_library(lib) { match has_library(lib) {
@ -53,7 +55,7 @@ pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool {
} }
pub fn has_library(p: &Path) -> Option<~str> { pub fn has_library(p: &Path) -> Option<~str> {
let files = os::list_dir(p); let files = do io::ignore_io_error { file::readdir(p) };
for path in files.iter() { for path in files.iter() {
if path.extension_str() == Some(os::consts::DLL_EXTENSION) { if path.extension_str() == Some(os::consts::DLL_EXTENSION) {
let stuff : &str = path.filestem_str().expect("has_library: weird path"); let stuff : &str = path.filestem_str().expect("has_library: weird path");

View file

@ -26,6 +26,8 @@ extern mod syntax;
use std::{os, result, run, str, task}; use std::{os, result, run, str, task};
use std::hashmap::HashSet; use std::hashmap::HashSet;
use std::rt::io;
use std::rt::io::file;
pub use std::path::Path; pub use std::path::Path;
use extra::workcache; use extra::workcache;
@ -36,7 +38,7 @@ use extra::{getopts};
use syntax::{ast, diagnostic}; use syntax::{ast, diagnostic};
use messages::{error, warn, note}; use messages::{error, warn, note};
use path_util::{build_pkg_id_in_workspace, built_test_in_workspace}; use path_util::{build_pkg_id_in_workspace, built_test_in_workspace};
use path_util::{U_RWX, in_rust_path}; use path_util::in_rust_path;
use path_util::{built_executable_in_workspace, built_library_in_workspace, default_workspace}; use path_util::{built_executable_in_workspace, built_library_in_workspace, default_workspace};
use path_util::{target_executable_in_workspace, target_library_in_workspace, dir_has_crate_file}; use path_util::{target_executable_in_workspace, target_library_in_workspace, dir_has_crate_file};
use source_control::{CheckedOutSources, is_git_dir, make_read_only}; use source_control::{CheckedOutSources, is_git_dir, make_read_only};
@ -513,7 +515,7 @@ impl CtxMethods for BuildContext {
// We expect that p is relative to the package source's start directory, // We expect that p is relative to the package source's start directory,
// so check that assumption // so check that assumption
debug!("JustOne: p = {}", p.display()); debug!("JustOne: p = {}", p.display());
assert!(os::path_exists(&pkg_src.start_dir.join(p))); assert!(pkg_src.start_dir.join(p).exists());
if is_lib(p) { if is_lib(p) {
PkgSrc::push_crate(&mut pkg_src.libs, 0, p); PkgSrc::push_crate(&mut pkg_src.libs, 0, p);
} else if is_main(p) { } else if is_main(p) {
@ -541,8 +543,8 @@ impl CtxMethods for BuildContext {
let dir = build_pkg_id_in_workspace(id, workspace); let dir = build_pkg_id_in_workspace(id, workspace);
note(format!("Cleaning package {} (removing directory {})", note(format!("Cleaning package {} (removing directory {})",
id.to_str(), dir.display())); id.to_str(), dir.display()));
if os::path_exists(&dir) { if dir.exists() {
os::remove_dir_recursive(&dir); file::rmdir_recursive(&dir);
note(format!("Removed directory {}", dir.display())); note(format!("Removed directory {}", dir.display()));
} }
@ -600,7 +602,6 @@ impl CtxMethods for BuildContext {
build_inputs: &[Path], build_inputs: &[Path],
target_workspace: &Path, target_workspace: &Path,
id: &PkgId) -> ~[~str] { id: &PkgId) -> ~[~str] {
use conditions::copy_failed::cond;
debug!("install_no_build: assuming {} comes from {} with target {}", debug!("install_no_build: assuming {} comes from {} with target {}",
id.to_str(), build_workspace.display(), target_workspace.display()); id.to_str(), build_workspace.display(), target_workspace.display());
@ -659,10 +660,8 @@ impl CtxMethods for BuildContext {
for exec in subex.iter() { for exec in subex.iter() {
debug!("Copying: {} -> {}", exec.display(), sub_target_ex.display()); debug!("Copying: {} -> {}", exec.display(), sub_target_ex.display());
if !(os::mkdir_recursive(&sub_target_ex.dir_path(), U_RWX) && file::mkdir_recursive(&sub_target_ex.dir_path(), io::UserRWX);
os::copy_file(exec, &sub_target_ex)) { file::copy(exec, &sub_target_ex);
cond.raise(((*exec).clone(), sub_target_ex.clone()));
}
// FIXME (#9639): This needs to handle non-utf8 paths // FIXME (#9639): This needs to handle non-utf8 paths
exe_thing.discover_output("binary", exe_thing.discover_output("binary",
sub_target_ex.as_str().unwrap(), sub_target_ex.as_str().unwrap(),
@ -674,10 +673,8 @@ impl CtxMethods for BuildContext {
.clone().expect(format!("I built {} but apparently \ .clone().expect(format!("I built {} but apparently \
didn't install it!", lib.display())); didn't install it!", lib.display()));
target_lib.set_filename(lib.filename().expect("weird target lib")); target_lib.set_filename(lib.filename().expect("weird target lib"));
if !(os::mkdir_recursive(&target_lib.dir_path(), U_RWX) && file::mkdir_recursive(&target_lib.dir_path(), io::UserRWX);
os::copy_file(lib, &target_lib)) { file::copy(lib, &target_lib);
cond.raise(((*lib).clone(), target_lib.clone()));
}
debug!("3. discovering output {}", target_lib.display()); debug!("3. discovering output {}", target_lib.display());
exe_thing.discover_output("binary", exe_thing.discover_output("binary",
target_lib.as_str().unwrap(), target_lib.as_str().unwrap(),
@ -710,10 +707,10 @@ impl CtxMethods for BuildContext {
} }
fn init(&self) { fn init(&self) {
os::mkdir_recursive(&Path::new("src"), U_RWX); file::mkdir_recursive(&Path::new("src"), io::UserRWX);
os::mkdir_recursive(&Path::new("lib"), U_RWX); file::mkdir_recursive(&Path::new("bin"), io::UserRWX);
os::mkdir_recursive(&Path::new("bin"), U_RWX); file::mkdir_recursive(&Path::new("lib"), io::UserRWX);
os::mkdir_recursive(&Path::new("build"), U_RWX); file::mkdir_recursive(&Path::new("build"), io::UserRWX);
} }
fn uninstall(&self, _id: &str, _vers: Option<~str>) { fn uninstall(&self, _id: &str, _vers: Option<~str>) {

View file

@ -10,7 +10,6 @@
use version::{try_getting_version, try_getting_local_version, use version::{try_getting_version, try_getting_local_version,
Version, NoVersion, split_version}; Version, NoVersion, split_version};
use std::rt::io::Writer;
use std::hash::Streaming; use std::hash::Streaming;
use std::hash; use std::hash;

View file

@ -12,7 +12,8 @@ extern mod extra;
use target::*; use target::*;
use package_id::PkgId; use package_id::PkgId;
use std::path::Path; use std::rt::io;
use std::rt::io::file;
use std::os; use std::os;
use context::*; use context::*;
use crate::Crate; use crate::Crate;
@ -117,7 +118,7 @@ impl PkgSrc {
debug!("Checking dirs: {:?}", to_try.map(|p| p.display().to_str()).connect(":")); debug!("Checking dirs: {:?}", to_try.map(|p| p.display().to_str()).connect(":"));
let path = to_try.iter().find(|&d| os::path_exists(d)); let path = to_try.iter().find(|&d| d.exists());
// See the comments on the definition of PkgSrc // See the comments on the definition of PkgSrc
let mut build_in_destination = use_rust_path_hack; let mut build_in_destination = use_rust_path_hack;
@ -132,7 +133,7 @@ impl PkgSrc {
let package_id = PkgId::new(prefix.as_str().unwrap()); let package_id = PkgId::new(prefix.as_str().unwrap());
let path = build_dir.join(&package_id.path); let path = build_dir.join(&package_id.path);
debug!("in loop: checking if {} is a directory", path.display()); debug!("in loop: checking if {} is a directory", path.display());
if os::path_is_dir(&path) { if path.is_dir() {
let ps = PkgSrc::new(source_workspace, let ps = PkgSrc::new(source_workspace,
destination_workspace, destination_workspace,
use_rust_path_hack, use_rust_path_hack,
@ -237,7 +238,7 @@ impl PkgSrc {
debug!("For package id {}, returning {}", id.to_str(), dir.display()); debug!("For package id {}, returning {}", id.to_str(), dir.display());
if !os::path_is_dir(&dir) { if !dir.is_dir() {
cond.raise((id.clone(), ~"supplied path for package dir is a \ cond.raise((id.clone(), ~"supplied path for package dir is a \
non-directory")); non-directory"));
} }
@ -267,7 +268,7 @@ impl PkgSrc {
debug!("Checking whether {} (path = {}) exists locally. Cwd = {}, does it? {:?}", debug!("Checking whether {} (path = {}) exists locally. Cwd = {}, does it? {:?}",
pkgid.to_str(), pkgid.path.display(), pkgid.to_str(), pkgid.path.display(),
cwd.display(), cwd.display(),
os::path_exists(&pkgid.path)); pkgid.path.exists());
match safe_git_clone(&pkgid.path, &pkgid.version, local) { match safe_git_clone(&pkgid.path, &pkgid.version, local) {
CheckedOutSources => { CheckedOutSources => {
@ -300,7 +301,7 @@ impl PkgSrc {
// Move clone_target to local. // Move clone_target to local.
// First, create all ancestor directories. // First, create all ancestor directories.
let moved = make_dir_rwx_recursive(&local.dir_path()) let moved = make_dir_rwx_recursive(&local.dir_path())
&& os::rename_file(&clone_target, local); && io::result(|| file::rename(&clone_target, local)).is_ok();
if moved { Some(local.clone()) } if moved { Some(local.clone()) }
else { None } else { None }
} }
@ -312,7 +313,7 @@ impl PkgSrc {
pub fn package_script_option(&self) -> Option<Path> { pub fn package_script_option(&self) -> Option<Path> {
let maybe_path = self.start_dir.join("pkg.rs"); let maybe_path = self.start_dir.join("pkg.rs");
debug!("package_script_option: checking whether {} exists", maybe_path.display()); debug!("package_script_option: checking whether {} exists", maybe_path.display());
if os::path_exists(&maybe_path) { if maybe_path.exists() {
Some(maybe_path) Some(maybe_path)
} else { } else {
None None
@ -349,7 +350,7 @@ impl PkgSrc {
let prefix = self.start_dir.component_iter().len(); let prefix = self.start_dir.component_iter().len();
debug!("Matching against {}", self.id.short_name); debug!("Matching against {}", self.id.short_name);
do os::walk_dir(&self.start_dir) |pth| { do file::walk_dir(&self.start_dir) |pth| {
let maybe_known_crate_set = match pth.filename_str() { let maybe_known_crate_set = match pth.filename_str() {
Some(filename) if filter(filename) => match filename { Some(filename) if filter(filename) => match filename {
"lib.rs" => Some(&mut self.libs), "lib.rs" => Some(&mut self.libs),

View file

@ -18,8 +18,9 @@ use rustc::driver::driver::host_triple;
use std::libc; use std::libc;
use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR}; use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
use std::os::mkdir_recursive;
use std::os; use std::os;
use std::rt::io;
use std::rt::io::file;
use messages::*; use messages::*;
pub fn default_workspace() -> Path { pub fn default_workspace() -> Path {
@ -28,8 +29,8 @@ pub fn default_workspace() -> Path {
fail!("Empty RUST_PATH"); fail!("Empty RUST_PATH");
} }
let result = p[0]; let result = p[0];
if !os::path_is_dir(&result) { if !result.is_dir() {
os::mkdir_recursive(&result, U_RWX); file::mkdir_recursive(&result, io::UserRWX);
} }
result result
} }
@ -43,9 +44,13 @@ pub static U_RWX: i32 = (S_IRUSR | S_IWUSR | S_IXUSR) as i32;
/// Creates a directory that is readable, writeable, /// Creates a directory that is readable, writeable,
/// and executable by the user. Returns true iff creation /// and executable by the user. Returns true iff creation
/// succeeded. /// succeeded.
pub fn make_dir_rwx(p: &Path) -> bool { os::make_dir(p, U_RWX) } pub fn make_dir_rwx(p: &Path) -> bool {
io::result(|| file::mkdir(p, io::UserRWX)).is_ok()
}
pub fn make_dir_rwx_recursive(p: &Path) -> bool { os::mkdir_recursive(p, U_RWX) } pub fn make_dir_rwx_recursive(p: &Path) -> bool {
io::result(|| file::mkdir_recursive(p, io::UserRWX)).is_ok()
}
// n.b. The next three functions ignore the package version right // n.b. The next three functions ignore the package version right
// now. Should fix that. // now. Should fix that.
@ -59,15 +64,16 @@ pub fn workspace_contains_package_id(pkgid: &PkgId, workspace: &Path) -> bool {
pub fn workspace_contains_package_id_(pkgid: &PkgId, workspace: &Path, pub fn workspace_contains_package_id_(pkgid: &PkgId, workspace: &Path,
// Returns the directory it was actually found in // Returns the directory it was actually found in
workspace_to_src_dir: &fn(&Path) -> Path) -> Option<Path> { workspace_to_src_dir: &fn(&Path) -> Path) -> Option<Path> {
if !os::path_is_dir(workspace) { if !workspace.is_dir() {
return None; return None;
} }
let src_dir = workspace_to_src_dir(workspace); let src_dir = workspace_to_src_dir(workspace);
if !src_dir.is_dir() { return None }
let mut found = None; let mut found = None;
do os::walk_dir(&src_dir) |p| { do file::walk_dir(&src_dir) |p| {
if os::path_is_dir(p) { if p.is_dir() {
if *p == src_dir.join(&pkgid.path) || { if *p == src_dir.join(&pkgid.path) || {
let pf = p.filename_str(); let pf = p.filename_str();
do pf.iter().any |&g| { do pf.iter().any |&g| {
@ -125,7 +131,7 @@ pub fn built_executable_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<
result = mk_output_path(Main, Build, pkgid, result); result = mk_output_path(Main, Build, pkgid, result);
debug!("built_executable_in_workspace: checking whether {} exists", debug!("built_executable_in_workspace: checking whether {} exists",
result.display()); result.display());
if os::path_exists(&result) { if result.exists() {
Some(result) Some(result)
} }
else { else {
@ -152,7 +158,7 @@ fn output_in_workspace(pkgid: &PkgId, workspace: &Path, what: OutputType) -> Opt
result = mk_output_path(what, Build, pkgid, result); result = mk_output_path(what, Build, pkgid, result);
debug!("output_in_workspace: checking whether {} exists", debug!("output_in_workspace: checking whether {} exists",
result.display()); result.display());
if os::path_exists(&result) { if result.exists() {
Some(result) Some(result)
} }
else { else {
@ -210,7 +216,7 @@ pub fn system_library(sysroot: &Path, lib_name: &str) -> Option<Path> {
fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Option<Path> { fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Option<Path> {
debug!("Listing directory {}", dir_to_search.display()); debug!("Listing directory {}", dir_to_search.display());
let dir_contents = os::list_dir(dir_to_search); let dir_contents = do io::ignore_io_error { file::readdir(dir_to_search) };
debug!("dir has {:?} entries", dir_contents.len()); debug!("dir has {:?} entries", dir_contents.len());
let lib_prefix = format!("{}{}", os::consts::DLL_PREFIX, short_name); let lib_prefix = format!("{}{}", os::consts::DLL_PREFIX, short_name);
@ -294,7 +300,7 @@ pub fn target_executable_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
/// As a side effect, creates the lib-dir if it doesn't exist /// As a side effect, creates the lib-dir if it doesn't exist
pub fn target_library_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path { pub fn target_library_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
use conditions::bad_path::cond; use conditions::bad_path::cond;
if !os::path_is_dir(workspace) { if !workspace.is_dir() {
cond.raise(((*workspace).clone(), cond.raise(((*workspace).clone(),
format!("Workspace supplied to target_library_in_workspace \ format!("Workspace supplied to target_library_in_workspace \
is not a directory! {}", workspace.display()))); is not a directory! {}", workspace.display())));
@ -333,7 +339,7 @@ fn target_file_in_workspace(pkgid: &PkgId, workspace: &Path,
(Install, Lib) => target_lib_dir(workspace), (Install, Lib) => target_lib_dir(workspace),
(Install, _) => target_bin_dir(workspace) (Install, _) => target_bin_dir(workspace)
}; };
if !os::path_exists(&result) && !mkdir_recursive(&result, U_RWX) { if io::result(|| file::mkdir_recursive(&result, io::UserRWX)).is_err() {
cond.raise((result.clone(), format!("target_file_in_workspace couldn't \ cond.raise((result.clone(), format!("target_file_in_workspace couldn't \
create the {} dir (pkgid={}, workspace={}, what={:?}, where={:?}", create the {} dir (pkgid={}, workspace={}, what={:?}, where={:?}",
subdir, pkgid.to_str(), workspace.display(), what, where))); subdir, pkgid.to_str(), workspace.display(), what, where)));
@ -344,18 +350,12 @@ fn target_file_in_workspace(pkgid: &PkgId, workspace: &Path,
/// Return the directory for <pkgid>'s build artifacts in <workspace>. /// Return the directory for <pkgid>'s build artifacts in <workspace>.
/// Creates it if it doesn't exist. /// Creates it if it doesn't exist.
pub fn build_pkg_id_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path { pub fn build_pkg_id_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
use conditions::bad_path::cond;
let mut result = target_build_dir(workspace); let mut result = target_build_dir(workspace);
result.push(&pkgid.path); result.push(&pkgid.path);
debug!("Creating build dir {} for package id {}", result.display(), debug!("Creating build dir {} for package id {}", result.display(),
pkgid.to_str()); pkgid.to_str());
if os::path_exists(&result) || os::mkdir_recursive(&result, U_RWX) { file::mkdir_recursive(&result, io::UserRWX);
result return result;
}
else {
cond.raise((result, format!("Could not create directory for package {}", pkgid.to_str())))
}
} }
/// Return the output file for a given directory name, /// Return the output file for a given directory name,
@ -398,13 +398,13 @@ pub fn mk_output_path(what: OutputType, where: Target,
pub fn uninstall_package_from(workspace: &Path, pkgid: &PkgId) { pub fn uninstall_package_from(workspace: &Path, pkgid: &PkgId) {
let mut did_something = false; let mut did_something = false;
let installed_bin = target_executable_in_workspace(pkgid, workspace); let installed_bin = target_executable_in_workspace(pkgid, workspace);
if os::path_exists(&installed_bin) { if installed_bin.exists() {
os::remove_file(&installed_bin); file::unlink(&installed_bin);
did_something = true; did_something = true;
} }
let installed_lib = target_library_in_workspace(pkgid, workspace); let installed_lib = target_library_in_workspace(pkgid, workspace);
if os::path_exists(&installed_lib) { if installed_lib.exists() {
os::remove_file(&installed_lib); file::unlink(&installed_lib);
did_something = true; did_something = true;
} }
if !did_something { if !did_something {
@ -421,7 +421,7 @@ pub fn dir_has_crate_file(dir: &Path) -> bool {
fn dir_has_file(dir: &Path, file: &str) -> bool { fn dir_has_file(dir: &Path, file: &str) -> bool {
assert!(dir.is_absolute()); assert!(dir.is_absolute());
os::path_exists(&dir.join(file)) dir.join(file).exists()
} }
pub fn find_dir_using_rust_path_hack(p: &PkgId) -> Option<Path> { pub fn find_dir_using_rust_path_hack(p: &PkgId) -> Option<Path> {

View file

@ -10,8 +10,9 @@
// Utils for working with version control repositories. Just git right now. // Utils for working with version control repositories. Just git right now.
use std::{os, run, str}; use std::{run, str};
use std::run::{ProcessOutput, ProcessOptions, Process}; use std::run::{ProcessOutput, ProcessOptions, Process};
use std::rt::io::file;
use extra::tempfile::TempDir; use extra::tempfile::TempDir;
use version::*; use version::*;
use path_util::chmod_read_only; use path_util::chmod_read_only;
@ -22,14 +23,14 @@ use path_util::chmod_read_only;
/// directory (that the callee may use, for example, to check out remote sources into). /// directory (that the callee may use, for example, to check out remote sources into).
/// Returns `CheckedOutSources` if the clone succeeded. /// Returns `CheckedOutSources` if the clone succeeded.
pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult { pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult {
if os::path_exists(source) { if source.exists() {
debug!("{} exists locally! Cloning it into {}", debug!("{} exists locally! Cloning it into {}",
source.display(), target.display()); source.display(), target.display());
// Ok to use target here; we know it will succeed // Ok to use target here; we know it will succeed
assert!(os::path_is_dir(source)); assert!(source.is_dir());
assert!(is_git_dir(source)); assert!(is_git_dir(source));
if !os::path_exists(target) { if !target.exists() {
debug!("Running: git clone {} {}", source.display(), target.display()); debug!("Running: git clone {} {}", source.display(), target.display());
// FIXME (#9639): This needs to handle non-utf8 paths // FIXME (#9639): This needs to handle non-utf8 paths
let outp = run::process_output("git", [~"clone", let outp = run::process_output("git", [~"clone",
@ -95,8 +96,8 @@ pub enum CloneResult {
pub fn make_read_only(target: &Path) { pub fn make_read_only(target: &Path) {
// Now, make all the files in the target dir read-only // Now, make all the files in the target dir read-only
do os::walk_dir(target) |p| { do file::walk_dir(target) |p| {
if !os::path_is_dir(p) { if !p.is_dir() {
assert!(chmod_read_only(p)); assert!(chmod_read_only(p));
}; };
true true
@ -138,5 +139,5 @@ fn process_output_in_cwd(prog: &str, args: &[~str], cwd: &Path) -> ProcessOutput
} }
pub fn is_git_dir(p: &Path) -> bool { pub fn is_git_dir(p: &Path) -> bool {
os::path_is_dir(&p.join(".git")) p.join(".git").is_dir()
} }

View file

@ -13,8 +13,7 @@
use context::{BuildContext, Context, RustcFlags}; use context::{BuildContext, Context, RustcFlags};
use std::{os, run, str, task}; use std::{os, run, str, task};
use std::rt::io; use std::rt::io;
use std::rt::io::Writer; use std::rt::io::file;
use std::rt::io::file::FileInfo;
use extra::arc::Arc; use extra::arc::Arc;
use extra::arc::RWArc; use extra::arc::RWArc;
use extra::tempfile::TempDir; use extra::tempfile::TempDir;
@ -27,7 +26,7 @@ use installed_packages::list_installed_packages;
use package_id::{PkgId}; use package_id::{PkgId};
use version::{ExactRevision, NoVersion, Version, Tagged}; use version::{ExactRevision, NoVersion, Version, Tagged};
use path_util::{target_executable_in_workspace, target_test_in_workspace, use path_util::{target_executable_in_workspace, target_test_in_workspace,
target_bench_in_workspace, make_dir_rwx, U_RWX, target_bench_in_workspace, make_dir_rwx,
library_in_workspace, installed_library_in_workspace, library_in_workspace, installed_library_in_workspace,
built_bench_in_workspace, built_test_in_workspace, built_bench_in_workspace, built_test_in_workspace,
built_library_in_workspace, built_executable_in_workspace, target_build_dir, built_library_in_workspace, built_executable_in_workspace, target_build_dir,
@ -84,7 +83,7 @@ fn git_repo_pkg_with_tag(a_tag: ~str) -> PkgId {
} }
fn writeFile(file_path: &Path, contents: &str) { fn writeFile(file_path: &Path, contents: &str) {
let mut out = file_path.open_writer(io::CreateOrTruncate); let mut out = file::create(file_path);
out.write(contents.as_bytes()); out.write(contents.as_bytes());
out.write(['\n' as u8]); out.write(['\n' as u8]);
} }
@ -92,7 +91,7 @@ fn writeFile(file_path: &Path, contents: &str) {
fn mk_emptier_workspace(tag: &str) -> TempDir { fn mk_emptier_workspace(tag: &str) -> TempDir {
let workspace = TempDir::new(tag).expect("couldn't create temp dir"); let workspace = TempDir::new(tag).expect("couldn't create temp dir");
let package_dir = workspace.path().join("src"); let package_dir = workspace.path().join("src");
assert!(os::mkdir_recursive(&package_dir, U_RWX)); file::mkdir_recursive(&package_dir, io::UserRWX);
workspace workspace
} }
@ -107,7 +106,7 @@ fn mk_workspace(workspace: &Path, short_name: &Path, version: &Version) -> Path
// FIXME (#9639): This needs to handle non-utf8 paths // FIXME (#9639): This needs to handle non-utf8 paths
let package_dir = workspace.join_many([~"src", format!("{}-{}", let package_dir = workspace.join_many([~"src", format!("{}-{}",
short_name.as_str().unwrap(), version.to_str())]); short_name.as_str().unwrap(), version.to_str())]);
assert!(os::mkdir_recursive(&package_dir, U_RWX)); file::mkdir_recursive(&package_dir, io::UserRWX);
package_dir package_dir
} }
@ -120,12 +119,12 @@ fn mk_temp_workspace(short_name: &Path, version: &Version) -> (TempDir, Path) {
version.to_str())]); version.to_str())]);
debug!("Created {} and does it exist? {:?}", package_dir.display(), debug!("Created {} and does it exist? {:?}", package_dir.display(),
os::path_is_dir(&package_dir)); package_dir.is_dir());
// Create main, lib, test, and bench files // Create main, lib, test, and bench files
debug!("mk_workspace: creating {}", package_dir.display()); debug!("mk_workspace: creating {}", package_dir.display());
assert!(os::mkdir_recursive(&package_dir, U_RWX)); file::mkdir_recursive(&package_dir, io::UserRWX);
debug!("Created {} and does it exist? {:?}", package_dir.display(), debug!("Created {} and does it exist? {:?}", package_dir.display(),
os::path_is_dir(&package_dir)); package_dir.is_dir());
// Create main, lib, test, and bench files // Create main, lib, test, and bench files
writeFile(&package_dir.join("main.rs"), writeFile(&package_dir.join("main.rs"),
@ -162,7 +161,7 @@ fn init_git_repo(p: &Path) -> TempDir {
let tmp = TempDir::new("git_local").expect("couldn't create temp dir"); let tmp = TempDir::new("git_local").expect("couldn't create temp dir");
let work_dir = tmp.path().join(p); let work_dir = tmp.path().join(p);
let work_dir_for_opts = work_dir.clone(); let work_dir_for_opts = work_dir.clone();
assert!(os::mkdir_recursive(&work_dir, U_RWX)); file::mkdir_recursive(&work_dir, io::UserRWX);
debug!("Running: git init in {}", work_dir.display()); debug!("Running: git init in {}", work_dir.display());
run_git([~"init"], None, &work_dir_for_opts, run_git([~"init"], None, &work_dir_for_opts,
format!("Couldn't initialize git repository in {}", work_dir.display())); format!("Couldn't initialize git repository in {}", work_dir.display()));
@ -199,25 +198,21 @@ fn add_git_tag(repo: &Path, tag: ~str) {
fn is_rwx(p: &Path) -> bool { fn is_rwx(p: &Path) -> bool {
use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR}; use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
match p.get_mode() { if !p.exists() { return false }
None => return false, let m = p.stat().mode;
Some(m) => (m & S_IRUSR as u64) == S_IRUSR as u64
((m & S_IRUSR as uint) == S_IRUSR as uint && (m & S_IWUSR as u64) == S_IWUSR as u64
&& (m & S_IWUSR as uint) == S_IWUSR as uint && (m & S_IXUSR as u64) == S_IXUSR as u64
&& (m & S_IXUSR as uint) == S_IXUSR as uint)
}
} }
fn is_read_only(p: &Path) -> bool { fn is_read_only(p: &Path) -> bool {
use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR}; use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
match p.get_mode() { if !p.exists() { return false }
None => return false, let m = p.stat().mode;
Some(m) => (m & S_IRUSR as u64) == S_IRUSR as u64
((m & S_IRUSR as uint) == S_IRUSR as uint && (m & S_IWUSR as u64) == 0 as u64
&& (m & S_IWUSR as uint) == 0 as uint && (m & S_IXUSR as u64) == 0 as u64
&& (m & S_IXUSR as uint) == 0 as uint)
}
} }
fn test_sysroot() -> Path { fn test_sysroot() -> Path {
@ -289,7 +284,7 @@ fn command_line_test_with_env(args: &[~str], cwd: &Path, env: Option<~[(~str, ~s
None => ~"" None => ~""
}; };
debug!("{} cd {}; {} {}", env_str, cwd.display(), cmd, args.connect(" ")); debug!("{} cd {}; {} {}", env_str, cwd.display(), cmd, args.connect(" "));
assert!(os::path_is_dir(&*cwd)); assert!(cwd.is_dir());
let cwd = (*cwd).clone(); let cwd = (*cwd).clone();
let mut prog = run::Process::new(cmd, args, run::ProcessOptions { let mut prog = run::Process::new(cmd, args, run::ProcessOptions {
env: env.map(|e| e + os::env()), env: env.map(|e| e + os::env()),
@ -325,9 +320,9 @@ fn create_local_package_in(pkgid: &PkgId, pkgdir: &Path) -> Path {
let package_dir = pkgdir.join_many([~"src", pkgid.to_str()]); let package_dir = pkgdir.join_many([~"src", pkgid.to_str()]);
// Create main, lib, test, and bench files // Create main, lib, test, and bench files
assert!(os::mkdir_recursive(&package_dir, U_RWX)); file::mkdir_recursive(&package_dir, io::UserRWX);
debug!("Created {} and does it exist? {:?}", package_dir.display(), debug!("Created {} and does it exist? {:?}", package_dir.display(),
os::path_is_dir(&package_dir)); package_dir.is_dir());
// Create main, lib, test, and bench files // Create main, lib, test, and bench files
writeFile(&package_dir.join("main.rs"), writeFile(&package_dir.join("main.rs"),
@ -378,7 +373,7 @@ fn lib_exists(repo: &Path, pkg_path: &Path, _v: Version) -> bool { // ??? versio
debug!("assert_lib_exists: checking whether {:?} exists", lib); debug!("assert_lib_exists: checking whether {:?} exists", lib);
lib.is_some() && { lib.is_some() && {
let libname = lib.get_ref(); let libname = lib.get_ref();
os::path_exists(libname) && is_rwx(libname) libname.exists() && is_rwx(libname)
} }
} }
@ -389,21 +384,21 @@ fn assert_executable_exists(repo: &Path, short_name: &str) {
fn executable_exists(repo: &Path, short_name: &str) -> bool { fn executable_exists(repo: &Path, short_name: &str) -> bool {
debug!("executable_exists: repo = {}, short_name = {}", repo.display(), short_name); debug!("executable_exists: repo = {}, short_name = {}", repo.display(), short_name);
let exec = target_executable_in_workspace(&PkgId::new(short_name), repo); let exec = target_executable_in_workspace(&PkgId::new(short_name), repo);
os::path_exists(&exec) && is_rwx(&exec) exec.exists() && is_rwx(&exec)
} }
fn test_executable_exists(repo: &Path, short_name: &str) -> bool { fn test_executable_exists(repo: &Path, short_name: &str) -> bool {
debug!("test_executable_exists: repo = {}, short_name = {}", repo.display(), short_name); debug!("test_executable_exists: repo = {}, short_name = {}", repo.display(), short_name);
let exec = built_test_in_workspace(&PkgId::new(short_name), repo); let exec = built_test_in_workspace(&PkgId::new(short_name), repo);
do exec.map_default(false) |exec| { do exec.map_default(false) |exec| {
os::path_exists(&exec) && is_rwx(&exec) exec.exists() && is_rwx(&exec)
} }
} }
fn remove_executable_file(p: &PkgId, workspace: &Path) { fn remove_executable_file(p: &PkgId, workspace: &Path) {
let exec = target_executable_in_workspace(&PkgId::new(p.short_name), workspace); let exec = target_executable_in_workspace(&PkgId::new(p.short_name), workspace);
if os::path_exists(&exec) { if exec.exists() {
assert!(os::remove_file(&exec)); file::unlink(&exec);
} }
} }
@ -417,14 +412,14 @@ fn built_executable_exists(repo: &Path, short_name: &str) -> bool {
let exec = built_executable_in_workspace(&PkgId::new(short_name), repo); let exec = built_executable_in_workspace(&PkgId::new(short_name), repo);
exec.is_some() && { exec.is_some() && {
let execname = exec.get_ref(); let execname = exec.get_ref();
os::path_exists(execname) && is_rwx(execname) execname.exists() && is_rwx(execname)
} }
} }
fn remove_built_executable_file(p: &PkgId, workspace: &Path) { fn remove_built_executable_file(p: &PkgId, workspace: &Path) {
let exec = built_executable_in_workspace(&PkgId::new(p.short_name), workspace); let exec = built_executable_in_workspace(&PkgId::new(p.short_name), workspace);
match exec { match exec {
Some(r) => assert!(os::remove_file(&r)), Some(r) => file::unlink(&r),
None => () None => ()
} }
} }
@ -446,8 +441,9 @@ fn llvm_bitcode_file_exists(repo: &Path, short_name: &str) -> bool {
} }
fn file_exists(repo: &Path, short_name: &str, extension: &str) -> bool { fn file_exists(repo: &Path, short_name: &str, extension: &str) -> bool {
os::path_exists(&target_build_dir(repo).join_many([short_name.to_owned(), target_build_dir(repo).join_many([short_name.to_owned(),
format!("{}.{}", short_name, extension)])) format!("{}.{}", short_name, extension)])
.exists()
} }
fn assert_built_library_exists(repo: &Path, short_name: &str) { fn assert_built_library_exists(repo: &Path, short_name: &str) {
@ -459,7 +455,7 @@ fn built_library_exists(repo: &Path, short_name: &str) -> bool {
let lib = built_library_in_workspace(&PkgId::new(short_name), repo); let lib = built_library_in_workspace(&PkgId::new(short_name), repo);
lib.is_some() && { lib.is_some() && {
let libname = lib.get_ref(); let libname = lib.get_ref();
os::path_exists(libname) && is_rwx(libname) libname.exists() && is_rwx(libname)
} }
} }
@ -508,7 +504,7 @@ fn output_file_name(workspace: &Path, short_name: ~str) -> Path {
fn touch_source_file(workspace: &Path, pkgid: &PkgId) { fn touch_source_file(workspace: &Path, pkgid: &PkgId) {
use conditions::bad_path::cond; use conditions::bad_path::cond;
let pkg_src_dir = workspace.join_many([~"src", pkgid.to_str()]); let pkg_src_dir = workspace.join_many([~"src", pkgid.to_str()]);
let contents = os::list_dir_path(&pkg_src_dir); let contents = file::readdir(&pkg_src_dir);
for p in contents.iter() { for p in contents.iter() {
if p.extension_str() == Some("rs") { if p.extension_str() == Some("rs") {
// should be able to do this w/o a process // should be able to do this w/o a process
@ -527,7 +523,7 @@ fn touch_source_file(workspace: &Path, pkgid: &PkgId) {
fn touch_source_file(workspace: &Path, pkgid: &PkgId) { fn touch_source_file(workspace: &Path, pkgid: &PkgId) {
use conditions::bad_path::cond; use conditions::bad_path::cond;
let pkg_src_dir = workspace.join_many([~"src", pkgid.to_str()]); let pkg_src_dir = workspace.join_many([~"src", pkgid.to_str()]);
let contents = os::list_dir_path(&pkg_src_dir); let contents = file::readdir(&pkg_src_dir);
for p in contents.iter() { for p in contents.iter() {
if p.extension_str() == Some("rs") { if p.extension_str() == Some("rs") {
// should be able to do this w/o a process // should be able to do this w/o a process
@ -548,7 +544,7 @@ fn frob_source_file(workspace: &Path, pkgid: &PkgId, filename: &str) {
let mut maybe_p = None; let mut maybe_p = None;
let maybe_file = pkg_src_dir.join(filename); let maybe_file = pkg_src_dir.join(filename);
debug!("Trying to frob {} -- {}", pkg_src_dir.display(), filename); debug!("Trying to frob {} -- {}", pkg_src_dir.display(), filename);
if os::path_exists(&maybe_file) { if maybe_file.exists() {
maybe_p = Some(maybe_file); maybe_p = Some(maybe_file);
} }
debug!("Frobbed? {:?}", maybe_p); debug!("Frobbed? {:?}", maybe_p);
@ -557,7 +553,7 @@ fn frob_source_file(workspace: &Path, pkgid: &PkgId, filename: &str) {
do io::io_error::cond.trap(|e| { do io::io_error::cond.trap(|e| {
cond.raise((p.clone(), format!("Bad path: {}", e.desc))); cond.raise((p.clone(), format!("Bad path: {}", e.desc)));
}).inside { }).inside {
let mut w = p.open_writer(io::Append); let mut w = file::open_stream(p, io::Append, io::Write);
w.write(bytes!("/* hi */\n")); w.write(bytes!("/* hi */\n"));
} }
} }
@ -570,13 +566,14 @@ fn frob_source_file(workspace: &Path, pkgid: &PkgId, filename: &str) {
fn test_make_dir_rwx() { fn test_make_dir_rwx() {
let temp = &os::tmpdir(); let temp = &os::tmpdir();
let dir = temp.join("quux"); let dir = temp.join("quux");
assert!(!os::path_exists(&dir) || if dir.exists() {
os::remove_dir_recursive(&dir)); file::rmdir_recursive(&dir);
}
debug!("Trying to make {}", dir.display()); debug!("Trying to make {}", dir.display());
assert!(make_dir_rwx(&dir)); assert!(make_dir_rwx(&dir));
assert!(os::path_is_dir(&dir)); assert!(dir.is_dir());
assert!(is_rwx(&dir)); assert!(is_rwx(&dir));
assert!(os::remove_dir_recursive(&dir)); file::rmdir_recursive(&dir);
} }
// n.b. I ignored the next two tests for now because something funny happens on linux // n.b. I ignored the next two tests for now because something funny happens on linux
@ -603,19 +600,19 @@ fn test_install_valid() {
// Check that all files exist // Check that all files exist
let exec = target_executable_in_workspace(&temp_pkg_id, temp_workspace); let exec = target_executable_in_workspace(&temp_pkg_id, temp_workspace);
debug!("exec = {}", exec.display()); debug!("exec = {}", exec.display());
assert!(os::path_exists(&exec)); assert!(exec.exists());
assert!(is_rwx(&exec)); assert!(is_rwx(&exec));
let lib = installed_library_in_workspace(&temp_pkg_id.path, temp_workspace); let lib = installed_library_in_workspace(&temp_pkg_id.path, temp_workspace);
debug!("lib = {:?}", lib); debug!("lib = {:?}", lib);
assert!(lib.as_ref().map_default(false, |l| os::path_exists(l))); assert!(lib.as_ref().map_default(false, |l| l.exists()));
assert!(lib.as_ref().map_default(false, |l| is_rwx(l))); assert!(lib.as_ref().map_default(false, |l| is_rwx(l)));
// And that the test and bench executables aren't installed // And that the test and bench executables aren't installed
assert!(!os::path_exists(&target_test_in_workspace(&temp_pkg_id, temp_workspace))); assert!(!target_test_in_workspace(&temp_pkg_id, temp_workspace).exists());
let bench = target_bench_in_workspace(&temp_pkg_id, temp_workspace); let bench = target_bench_in_workspace(&temp_pkg_id, temp_workspace);
debug!("bench = {}", bench.display()); debug!("bench = {}", bench.display());
assert!(!os::path_exists(&bench)); assert!(!bench.exists());
// Make sure the db isn't dirty, so that it doesn't try to save() // Make sure the db isn't dirty, so that it doesn't try to save()
// asynchronously after the temporary directory that it wants to save // asynchronously after the temporary directory that it wants to save
@ -655,19 +652,19 @@ fn test_install_valid_external() {
// Check that all files exist // Check that all files exist
let exec = target_executable_in_workspace(&temp_pkg_id, temp_workspace); let exec = target_executable_in_workspace(&temp_pkg_id, temp_workspace);
debug!("exec = {}", exec.display()); debug!("exec = {}", exec.display());
assert!(os::path_exists(&exec)); assert!(exec.exists());
assert!(is_rwx(&exec)); assert!(is_rwx(&exec));
let lib = installed_library_in_workspace(&temp_pkg_id.path, temp_workspace); let lib = installed_library_in_workspace(&temp_pkg_id.path, temp_workspace);
debug!("lib = {:?}", lib); debug!("lib = {:?}", lib);
assert!(lib.as_ref().map_default(false, |l| os::path_exists(l))); assert!(lib.as_ref().map_default(false, |l| l.exists()));
assert!(lib.as_ref().map_default(false, |l| is_rwx(l))); assert!(lib.as_ref().map_default(false, |l| is_rwx(l)));
// And that the test and bench executables aren't installed // And that the test and bench executables aren't installed
assert!(!os::path_exists(&target_test_in_workspace(&temp_pkg_id, temp_workspace))); assert!(!target_test_in_workspace(&temp_pkg_id, temp_workspace).exists());
let bench = target_bench_in_workspace(&temp_pkg_id, temp_workspace); let bench = target_bench_in_workspace(&temp_pkg_id, temp_workspace);
debug!("bench = {}", bench.display()); debug!("bench = {}", bench.display());
assert!(!os::path_exists(&bench)); assert!(!bench.exists());
} }
@ -711,7 +708,7 @@ fn test_install_git() {
debug!("Checking for files in {}", ws.display()); debug!("Checking for files in {}", ws.display());
let exec = target_executable_in_workspace(&temp_pkg_id, &ws); let exec = target_executable_in_workspace(&temp_pkg_id, &ws);
debug!("exec = {}", exec.display()); debug!("exec = {}", exec.display());
assert!(os::path_exists(&exec)); assert!(exec.exists());
assert!(is_rwx(&exec)); assert!(is_rwx(&exec));
let _built_lib = let _built_lib =
built_library_in_workspace(&temp_pkg_id, built_library_in_workspace(&temp_pkg_id,
@ -719,17 +716,17 @@ fn test_install_git() {
assert_lib_exists(&ws, &temp_pkg_id.path, temp_pkg_id.version.clone()); assert_lib_exists(&ws, &temp_pkg_id.path, temp_pkg_id.version.clone());
let built_test = built_test_in_workspace(&temp_pkg_id, let built_test = built_test_in_workspace(&temp_pkg_id,
&ws).expect("test_install_git: built test should exist"); &ws).expect("test_install_git: built test should exist");
assert!(os::path_exists(&built_test)); assert!(built_test.exists());
let built_bench = built_bench_in_workspace(&temp_pkg_id, let built_bench = built_bench_in_workspace(&temp_pkg_id,
&ws).expect("test_install_git: built bench should exist"); &ws).expect("test_install_git: built bench should exist");
assert!(os::path_exists(&built_bench)); assert!(built_bench.exists());
// And that the test and bench executables aren't installed // And that the test and bench executables aren't installed
let test = target_test_in_workspace(&temp_pkg_id, &ws); let test = target_test_in_workspace(&temp_pkg_id, &ws);
assert!(!os::path_exists(&test)); assert!(!test.exists());
debug!("test = {}", test.display()); debug!("test = {}", test.display());
let bench = target_bench_in_workspace(&temp_pkg_id, &ws); let bench = target_bench_in_workspace(&temp_pkg_id, &ws);
debug!("bench = {}", bench.display()); debug!("bench = {}", bench.display());
assert!(!os::path_exists(&bench)); assert!(!bench.exists());
} }
#[test] #[test]
@ -783,6 +780,7 @@ fn test_package_version() {
let repo = repo.path(); let repo = repo.path();
let repo_subdir = repo.join_many(["mockgithub.com", "catamorphism", "test_pkg_version"]); let repo_subdir = repo.join_many(["mockgithub.com", "catamorphism", "test_pkg_version"]);
debug!("Writing files in: {}", repo_subdir.display()); debug!("Writing files in: {}", repo_subdir.display());
file::mkdir_recursive(&repo_subdir, io::UserRWX);
writeFile(&repo_subdir.join("main.rs"), writeFile(&repo_subdir.join("main.rs"),
"fn main() { let _x = (); }"); "fn main() { let _x = (); }");
writeFile(&repo_subdir.join("lib.rs"), writeFile(&repo_subdir.join("lib.rs"),
@ -853,9 +851,9 @@ fn test_package_request_version() {
let mut dir = target_build_dir(&repo.join(".rust")); let mut dir = target_build_dir(&repo.join(".rust"));
dir.push(&Path::new("src/mockgithub.com/catamorphism/test_pkg_version-0.3")); dir.push(&Path::new("src/mockgithub.com/catamorphism/test_pkg_version-0.3"));
debug!("dir = {}", dir.display()); debug!("dir = {}", dir.display());
assert!(os::path_is_dir(&dir)); assert!(dir.is_dir());
assert!(os::path_exists(&dir.join("version-0.3-file.txt"))); assert!(dir.join("version-0.3-file.txt").exists());
assert!(!os::path_exists(&dir.join("version-0.4-file.txt"))); assert!(!dir.join("version-0.4-file.txt").exists());
} }
#[test] #[test]
@ -904,16 +902,13 @@ fn package_script_with_default_build() {
let source = Path::new(file!()).dir_path().join_many( let source = Path::new(file!()).dir_path().join_many(
[~"testsuite", ~"pass", ~"src", ~"fancy-lib", ~"pkg.rs"]); [~"testsuite", ~"pass", ~"src", ~"fancy-lib", ~"pkg.rs"]);
debug!("package_script_with_default_build: {}", source.display()); debug!("package_script_with_default_build: {}", source.display());
if !os::copy_file(&source, file::copy(&source, &dir.join_many(["src", "fancy-lib-0.1", "pkg.rs"]));
&dir.join_many(["src", "fancy-lib-0.1", "pkg.rs"])) {
fail!("Couldn't copy file");
}
command_line_test([~"install", ~"fancy-lib"], dir); command_line_test([~"install", ~"fancy-lib"], dir);
assert_lib_exists(dir, &Path::new("fancy-lib"), NoVersion); assert_lib_exists(dir, &Path::new("fancy-lib"), NoVersion);
assert!(os::path_exists(&target_build_dir(dir).join_many([~"fancy-lib", ~"generated.rs"]))); assert!(target_build_dir(dir).join_many([~"fancy-lib", ~"generated.rs"]).exists());
let generated_path = target_build_dir(dir).join_many([~"fancy-lib", ~"generated.rs"]); let generated_path = target_build_dir(dir).join_many([~"fancy-lib", ~"generated.rs"]);
debug!("generated path = {}", generated_path.display()); debug!("generated path = {}", generated_path.display());
assert!(os::path_exists(&generated_path)); assert!(generated_path.exists());
} }
#[test] #[test]
@ -921,7 +916,7 @@ fn rustpkg_build_no_arg() {
let tmp = TempDir::new("rustpkg_build_no_arg").expect("rustpkg_build_no_arg failed"); let tmp = TempDir::new("rustpkg_build_no_arg").expect("rustpkg_build_no_arg failed");
let tmp = tmp.path().join(".rust"); let tmp = tmp.path().join(".rust");
let package_dir = tmp.join_many(["src", "foo"]); let package_dir = tmp.join_many(["src", "foo"]);
assert!(os::mkdir_recursive(&package_dir, U_RWX)); file::mkdir_recursive(&package_dir, io::UserRWX);
writeFile(&package_dir.join("main.rs"), writeFile(&package_dir.join("main.rs"),
"fn main() { let _x = (); }"); "fn main() { let _x = (); }");
@ -935,7 +930,7 @@ fn rustpkg_install_no_arg() {
let tmp = TempDir::new("rustpkg_install_no_arg").expect("rustpkg_install_no_arg failed"); let tmp = TempDir::new("rustpkg_install_no_arg").expect("rustpkg_install_no_arg failed");
let tmp = tmp.path().join(".rust"); let tmp = tmp.path().join(".rust");
let package_dir = tmp.join_many(["src", "foo"]); let package_dir = tmp.join_many(["src", "foo"]);
assert!(os::mkdir_recursive(&package_dir, U_RWX)); file::mkdir_recursive(&package_dir, io::UserRWX);
writeFile(&package_dir.join("lib.rs"), writeFile(&package_dir.join("lib.rs"),
"fn main() { let _x = (); }"); "fn main() { let _x = (); }");
debug!("install_no_arg: dir = {}", package_dir.display()); debug!("install_no_arg: dir = {}", package_dir.display());
@ -948,7 +943,7 @@ fn rustpkg_clean_no_arg() {
let tmp = TempDir::new("rustpkg_clean_no_arg").expect("rustpkg_clean_no_arg failed"); let tmp = TempDir::new("rustpkg_clean_no_arg").expect("rustpkg_clean_no_arg failed");
let tmp = tmp.path().join(".rust"); let tmp = tmp.path().join(".rust");
let package_dir = tmp.join_many(["src", "foo"]); let package_dir = tmp.join_many(["src", "foo"]);
assert!(os::mkdir_recursive(&package_dir, U_RWX)); file::mkdir_recursive(&package_dir, io::UserRWX);
writeFile(&package_dir.join("main.rs"), writeFile(&package_dir.join("main.rs"),
"fn main() { let _x = (); }"); "fn main() { let _x = (); }");
@ -957,7 +952,7 @@ fn rustpkg_clean_no_arg() {
assert_built_executable_exists(&tmp, "foo"); assert_built_executable_exists(&tmp, "foo");
command_line_test([~"clean"], &package_dir); command_line_test([~"clean"], &package_dir);
let res = built_executable_in_workspace(&PkgId::new("foo"), &tmp); let res = built_executable_in_workspace(&PkgId::new("foo"), &tmp);
assert!(!res.as_ref().map_default(false, |m| { os::path_exists(m) })); assert!(!res.as_ref().map_default(false, |m| m.exists()));
} }
#[test] #[test]
@ -983,9 +978,9 @@ fn rust_path_test() {
fn rust_path_contents() { fn rust_path_contents() {
let dir = TempDir::new("rust_path").expect("rust_path_contents failed"); let dir = TempDir::new("rust_path").expect("rust_path_contents failed");
let abc = &dir.path().join_many(["A", "B", "C"]); let abc = &dir.path().join_many(["A", "B", "C"]);
assert!(os::mkdir_recursive(&abc.join(".rust"), U_RWX)); file::mkdir_recursive(&abc.join(".rust"), io::UserRWX);
assert!(os::mkdir_recursive(&abc.with_filename(".rust"), U_RWX)); file::mkdir_recursive(&abc.with_filename(".rust"), io::UserRWX);
assert!(os::mkdir_recursive(&abc.dir_path().with_filename(".rust"), U_RWX)); file::mkdir_recursive(&abc.dir_path().with_filename(".rust"), io::UserRWX);
assert!(os::change_dir(abc)); assert!(os::change_dir(abc));
let p = rust_path(); let p = rust_path();
@ -1225,8 +1220,8 @@ fn test_non_numeric_tag() {
temp_pkg_id.path.as_str().unwrap())], repo); temp_pkg_id.path.as_str().unwrap())], repo);
let file1 = repo.join_many(["mockgithub.com", "catamorphism", "test-pkg", "testbranch_only"]); let file1 = repo.join_many(["mockgithub.com", "catamorphism", "test-pkg", "testbranch_only"]);
let file2 = repo.join_many(["mockgithub.com", "catamorphism", "test-pkg", "master_only"]); let file2 = repo.join_many(["mockgithub.com", "catamorphism", "test-pkg", "master_only"]);
assert!(os::path_exists(&file1)); assert!(file1.exists());
assert!(!os::path_exists(&file2)); assert!(!file2.exists());
} }
#[test] #[test]
@ -1237,11 +1232,11 @@ fn test_extern_mod() {
let lib_depend_dir = TempDir::new("foo").expect("test_extern_mod"); let lib_depend_dir = TempDir::new("foo").expect("test_extern_mod");
let lib_depend_dir = lib_depend_dir.path(); let lib_depend_dir = lib_depend_dir.path();
let aux_dir = lib_depend_dir.join_many(["src", "mockgithub.com", "catamorphism", "test_pkg"]); let aux_dir = lib_depend_dir.join_many(["src", "mockgithub.com", "catamorphism", "test_pkg"]);
assert!(os::mkdir_recursive(&aux_dir, U_RWX)); file::mkdir_recursive(&aux_dir, io::UserRWX);
let aux_pkg_file = aux_dir.join("lib.rs"); let aux_pkg_file = aux_dir.join("lib.rs");
writeFile(&aux_pkg_file, "pub mod bar { pub fn assert_true() { assert!(true); } }\n"); writeFile(&aux_pkg_file, "pub mod bar { pub fn assert_true() { assert!(true); } }\n");
assert!(os::path_exists(&aux_pkg_file)); assert!(aux_pkg_file.exists());
writeFile(&main_file, writeFile(&main_file,
"extern mod test = \"mockgithub.com/catamorphism/test_pkg\";\nuse test::bar;\ "extern mod test = \"mockgithub.com/catamorphism/test_pkg\";\nuse test::bar;\
@ -1275,7 +1270,7 @@ fn test_extern_mod() {
str::from_utf8(outp.output), str::from_utf8(outp.output),
str::from_utf8(outp.error)); str::from_utf8(outp.error));
} }
assert!(os::path_exists(&exec_file) && is_executable(&exec_file)); assert!(exec_file.exists() && is_executable(&exec_file));
} }
#[test] #[test]
@ -1286,11 +1281,11 @@ fn test_extern_mod_simpler() {
let lib_depend_dir = TempDir::new("foo").expect("test_extern_mod_simpler"); let lib_depend_dir = TempDir::new("foo").expect("test_extern_mod_simpler");
let lib_depend_dir = lib_depend_dir.path(); let lib_depend_dir = lib_depend_dir.path();
let aux_dir = lib_depend_dir.join_many(["src", "rust-awesomeness"]); let aux_dir = lib_depend_dir.join_many(["src", "rust-awesomeness"]);
assert!(os::mkdir_recursive(&aux_dir, U_RWX)); file::mkdir_recursive(&aux_dir, io::UserRWX);
let aux_pkg_file = aux_dir.join("lib.rs"); let aux_pkg_file = aux_dir.join("lib.rs");
writeFile(&aux_pkg_file, "pub mod bar { pub fn assert_true() { assert!(true); } }\n"); writeFile(&aux_pkg_file, "pub mod bar { pub fn assert_true() { assert!(true); } }\n");
assert!(os::path_exists(&aux_pkg_file)); assert!(aux_pkg_file.exists());
writeFile(&main_file, writeFile(&main_file,
"extern mod test = \"rust-awesomeness\";\nuse test::bar;\ "extern mod test = \"rust-awesomeness\";\nuse test::bar;\
@ -1330,7 +1325,7 @@ fn test_extern_mod_simpler() {
str::from_utf8(outp.output), str::from_utf8(outp.output),
str::from_utf8(outp.error)); str::from_utf8(outp.error));
} }
assert!(os::path_exists(&exec_file) && is_executable(&exec_file)); assert!(exec_file.exists() && is_executable(&exec_file));
} }
#[test] #[test]
@ -1342,8 +1337,8 @@ fn test_import_rustpkg() {
"extern mod rustpkg; fn main() {}"); "extern mod rustpkg; fn main() {}");
command_line_test([~"build", ~"foo"], workspace); command_line_test([~"build", ~"foo"], workspace);
debug!("workspace = {}", workspace.display()); debug!("workspace = {}", workspace.display());
assert!(os::path_exists(&target_build_dir(workspace).join("foo").join(format!("pkg{}", assert!(target_build_dir(workspace).join("foo").join(format!("pkg{}",
os::EXE_SUFFIX)))); os::EXE_SUFFIX)).exists());
} }
#[test] #[test]
@ -1355,8 +1350,8 @@ fn test_macro_pkg_script() {
"extern mod rustpkg; fn main() { debug!(\"Hi\"); }"); "extern mod rustpkg; fn main() { debug!(\"Hi\"); }");
command_line_test([~"build", ~"foo"], workspace); command_line_test([~"build", ~"foo"], workspace);
debug!("workspace = {}", workspace.display()); debug!("workspace = {}", workspace.display());
assert!(os::path_exists(&target_build_dir(workspace).join("foo").join(format!("pkg{}", assert!(target_build_dir(workspace).join("foo").join(format!("pkg{}",
os::EXE_SUFFIX)))); os::EXE_SUFFIX)).exists());
} }
#[test] #[test]
@ -1436,7 +1431,7 @@ fn rust_path_hack_cwd() {
// Same as rust_path_hack_test, but the CWD is the dir to build out of // Same as rust_path_hack_test, but the CWD is the dir to build out of
let cwd = TempDir::new("foo").expect("rust_path_hack_cwd"); let cwd = TempDir::new("foo").expect("rust_path_hack_cwd");
let cwd = cwd.path().join("foo"); let cwd = cwd.path().join("foo");
assert!(os::mkdir_recursive(&cwd, U_RWX)); file::mkdir_recursive(&cwd, io::UserRWX);
writeFile(&cwd.join("lib.rs"), "pub fn f() { }"); writeFile(&cwd.join("lib.rs"), "pub fn f() { }");
let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace"); let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace");
@ -1456,7 +1451,7 @@ fn rust_path_hack_multi_path() {
// Same as rust_path_hack_test, but with a more complex package ID // Same as rust_path_hack_test, but with a more complex package ID
let cwd = TempDir::new("pkg_files").expect("rust_path_hack_cwd"); let cwd = TempDir::new("pkg_files").expect("rust_path_hack_cwd");
let subdir = cwd.path().join_many(["foo", "bar", "quux"]); let subdir = cwd.path().join_many(["foo", "bar", "quux"]);
assert!(os::mkdir_recursive(&subdir, U_RWX)); file::mkdir_recursive(&subdir, io::UserRWX);
writeFile(&subdir.join("lib.rs"), "pub fn f() { }"); writeFile(&subdir.join("lib.rs"), "pub fn f() { }");
let name = ~"foo/bar/quux"; let name = ~"foo/bar/quux";
@ -1870,21 +1865,22 @@ fn pkgid_pointing_to_subdir() {
// rustpkg should recognize that and treat the part after some_repo/ as a subdir // rustpkg should recognize that and treat the part after some_repo/ as a subdir
let workspace = TempDir::new("parent_repo").expect("Couldn't create temp dir"); let workspace = TempDir::new("parent_repo").expect("Couldn't create temp dir");
let workspace = workspace.path(); let workspace = workspace.path();
assert!(os::mkdir_recursive(&workspace.join_many(["src", "mockgithub.com", file::mkdir_recursive(&workspace.join_many(["src", "mockgithub.com",
"mozilla", "some_repo"]), U_RWX)); "mozilla", "some_repo"]),
io::UserRWX);
let foo_dir = workspace.join_many(["src", "mockgithub.com", "mozilla", "some_repo", let foo_dir = workspace.join_many(["src", "mockgithub.com", "mozilla", "some_repo",
"extras", "foo"]); "extras", "foo"]);
let bar_dir = workspace.join_many(["src", "mockgithub.com", "mozilla", "some_repo", let bar_dir = workspace.join_many(["src", "mockgithub.com", "mozilla", "some_repo",
"extras", "bar"]); "extras", "bar"]);
assert!(os::mkdir_recursive(&foo_dir, U_RWX)); file::mkdir_recursive(&foo_dir, io::UserRWX);
assert!(os::mkdir_recursive(&bar_dir, U_RWX)); file::mkdir_recursive(&bar_dir, io::UserRWX);
writeFile(&foo_dir.join("lib.rs"), "pub fn f() {}"); writeFile(&foo_dir.join("lib.rs"), "pub fn f() {}");
writeFile(&bar_dir.join("lib.rs"), "pub fn g() {}"); writeFile(&bar_dir.join("lib.rs"), "pub fn g() {}");
debug!("Creating a file in {}", workspace.display()); debug!("Creating a file in {}", workspace.display());
let testpkg_dir = workspace.join_many(["src", "testpkg-0.1"]); let testpkg_dir = workspace.join_many(["src", "testpkg-0.1"]);
assert!(os::mkdir_recursive(&testpkg_dir, U_RWX)); file::mkdir_recursive(&testpkg_dir, io::UserRWX);
writeFile(&testpkg_dir.join("main.rs"), writeFile(&testpkg_dir.join("main.rs"),
"extern mod foo = \"mockgithub.com/mozilla/some_repo/extras/foo\";\n "extern mod foo = \"mockgithub.com/mozilla/some_repo/extras/foo\";\n
@ -1957,9 +1953,9 @@ fn test_target_specific_build_dir() {
~"build", ~"build",
~"foo"], ~"foo"],
workspace); workspace);
assert!(os::path_is_dir(&target_build_dir(workspace))); assert!(target_build_dir(workspace).is_dir());
assert!(built_executable_exists(workspace, "foo")); assert!(built_executable_exists(workspace, "foo"));
assert!(os::list_dir(&workspace.join("build")).len() == 1); assert!(file::readdir(&workspace.join("build")).len() == 1);
} }
#[test] #[test]
@ -1973,10 +1969,10 @@ fn test_target_specific_install_dir() {
~"install", ~"install",
~"foo"], ~"foo"],
workspace); workspace);
assert!(os::path_is_dir(&workspace.join_many([~"lib", host_triple()]))); assert!(workspace.join_many([~"lib", host_triple()]).is_dir());
assert_lib_exists(workspace, &Path::new("foo"), NoVersion); assert_lib_exists(workspace, &Path::new("foo"), NoVersion);
assert!(os::list_dir(&workspace.join("lib")).len() == 1); assert!(file::readdir(&workspace.join("lib")).len() == 1);
assert!(os::path_is_dir(&workspace.join("bin"))); assert!(workspace.join("bin").is_dir());
assert_executable_exists(workspace, "foo"); assert_executable_exists(workspace, "foo");
} }
@ -1988,7 +1984,7 @@ fn test_dependencies_terminate() {
let workspace = workspace.path(); let workspace = workspace.path();
let b_dir = workspace.join_many(["src", "b-0.1"]); let b_dir = workspace.join_many(["src", "b-0.1"]);
let b_subdir = b_dir.join("test"); let b_subdir = b_dir.join("test");
assert!(os::mkdir_recursive(&b_subdir, U_RWX)); file::mkdir_recursive(&b_subdir, io::UserRWX);
writeFile(&b_subdir.join("test.rs"), writeFile(&b_subdir.join("test.rs"),
"extern mod b; use b::f; #[test] fn g() { f() }"); "extern mod b; use b::f; #[test] fn g() { f() }");
command_line_test([~"install", ~"b"], workspace); command_line_test([~"install", ~"b"], workspace);
@ -2161,19 +2157,19 @@ fn test_installed_read_only() {
debug!("Checking for files in {}", ws.display()); debug!("Checking for files in {}", ws.display());
let exec = target_executable_in_workspace(&temp_pkg_id, &ws); let exec = target_executable_in_workspace(&temp_pkg_id, &ws);
debug!("exec = {}", exec.display()); debug!("exec = {}", exec.display());
assert!(os::path_exists(&exec)); assert!(exec.exists());
assert!(is_rwx(&exec)); assert!(is_rwx(&exec));
let built_lib = let built_lib =
built_library_in_workspace(&temp_pkg_id, built_library_in_workspace(&temp_pkg_id,
&ws).expect("test_install_git: built lib should exist"); &ws).expect("test_install_git: built lib should exist");
assert!(os::path_exists(&built_lib)); assert!(built_lib.exists());
assert!(is_rwx(&built_lib)); assert!(is_rwx(&built_lib));
// Make sure sources are (a) under "build" and (b) read-only // Make sure sources are (a) under "build" and (b) read-only
let src1 = target_build_dir(&ws).join_many([~"src", temp_pkg_id.to_str(), ~"main.rs"]); let src1 = target_build_dir(&ws).join_many([~"src", temp_pkg_id.to_str(), ~"main.rs"]);
let src2 = target_build_dir(&ws).join_many([~"src", temp_pkg_id.to_str(), ~"lib.rs"]); let src2 = target_build_dir(&ws).join_many([~"src", temp_pkg_id.to_str(), ~"lib.rs"]);
assert!(os::path_exists(&src1)); assert!(src1.exists());
assert!(os::path_exists(&src2)); assert!(src2.exists());
assert!(is_read_only(&src1)); assert!(is_read_only(&src1));
assert!(is_read_only(&src2)); assert!(is_read_only(&src2));
} }
@ -2186,7 +2182,7 @@ fn test_installed_local_changes() {
debug!("repo = {}", repo.display()); debug!("repo = {}", repo.display());
let repo_subdir = repo.join_many(["mockgithub.com", "catamorphism", "test-pkg"]); let repo_subdir = repo.join_many(["mockgithub.com", "catamorphism", "test-pkg"]);
debug!("repo_subdir = {}", repo_subdir.display()); debug!("repo_subdir = {}", repo_subdir.display());
assert!(os::mkdir_recursive(&repo.join_many([".rust", "src"]), U_RWX)); file::mkdir_recursive(&repo.join_many([".rust", "src"]), io::UserRWX);
writeFile(&repo_subdir.join("main.rs"), writeFile(&repo_subdir.join("main.rs"),
"fn main() { let _x = (); }"); "fn main() { let _x = (); }");
@ -2269,7 +2265,7 @@ fn find_sources_in_cwd() {
let temp_dir = TempDir::new("sources").expect("find_sources_in_cwd failed"); let temp_dir = TempDir::new("sources").expect("find_sources_in_cwd failed");
let temp_dir = temp_dir.path(); let temp_dir = temp_dir.path();
let source_dir = temp_dir.join("foo"); let source_dir = temp_dir.join("foo");
os::mkdir_recursive(&source_dir, U_RWX); file::mkdir_recursive(&source_dir, io::UserRWX);
writeFile(&source_dir.join("main.rs"), writeFile(&source_dir.join("main.rs"),
"fn main() { let _x = (); }"); "fn main() { let _x = (); }");
command_line_test([~"install", ~"foo"], &source_dir); command_line_test([~"install", ~"foo"], &source_dir);
@ -2292,16 +2288,13 @@ fn test_c_dependency_ok() {
debug!("dir = {}", dir.display()); debug!("dir = {}", dir.display());
let source = Path::new(file!()).dir_path().join_many( let source = Path::new(file!()).dir_path().join_many(
[~"testsuite", ~"pass", ~"src", ~"c-dependencies", ~"pkg.rs"]); [~"testsuite", ~"pass", ~"src", ~"c-dependencies", ~"pkg.rs"]);
if !os::copy_file(&source, file::copy(&source, &dir.join_many([~"src", ~"cdep-0.1", ~"pkg.rs"]));
&dir.join_many([~"src", ~"cdep-0.1", ~"pkg.rs"])) {
fail!("Couldn't copy file");
}
command_line_test([~"build", ~"cdep"], dir); command_line_test([~"build", ~"cdep"], dir);
assert_executable_exists(dir, "cdep"); assert_executable_exists(dir, "cdep");
let out_dir = target_build_dir(dir).join("cdep"); let out_dir = target_build_dir(dir).join("cdep");
let c_library_path = out_dir.join(platform_library_name("foo")); let c_library_path = out_dir.join(platform_library_name("foo"));
debug!("c library path: {}", c_library_path.display()); debug!("c library path: {}", c_library_path.display());
assert!(os::path_exists(&c_library_path)); assert!(c_library_path.exists());
} }
#[test] #[test]
@ -2316,16 +2309,13 @@ fn test_c_dependency_no_rebuilding() {
debug!("dir = {}", dir.display()); debug!("dir = {}", dir.display());
let source = Path::new(file!()).dir_path().join_many( let source = Path::new(file!()).dir_path().join_many(
[~"testsuite", ~"pass", ~"src", ~"c-dependencies", ~"pkg.rs"]); [~"testsuite", ~"pass", ~"src", ~"c-dependencies", ~"pkg.rs"]);
if !os::copy_file(&source, file::copy(&source, &dir.join_many([~"src", ~"cdep-0.1", ~"pkg.rs"]));
&dir.join_many([~"src", ~"cdep-0.1", ~"pkg.rs"])) {
fail!("Couldn't copy file");
}
command_line_test([~"build", ~"cdep"], dir); command_line_test([~"build", ~"cdep"], dir);
assert_executable_exists(dir, "cdep"); assert_executable_exists(dir, "cdep");
let out_dir = target_build_dir(dir).join("cdep"); let out_dir = target_build_dir(dir).join("cdep");
let c_library_path = out_dir.join(platform_library_name("foo")); let c_library_path = out_dir.join(platform_library_name("foo"));
debug!("c library path: {}", c_library_path.display()); debug!("c library path: {}", c_library_path.display());
assert!(os::path_exists(&c_library_path)); assert!(c_library_path.exists());
// Now, make it read-only so rebuilding will fail // Now, make it read-only so rebuilding will fail
assert!(chmod_read_only(&c_library_path)); assert!(chmod_read_only(&c_library_path));
@ -2352,15 +2342,13 @@ fn test_c_dependency_yes_rebuilding() {
[~"testsuite", ~"pass", ~"src", ~"c-dependencies", ~"pkg.rs"]); [~"testsuite", ~"pass", ~"src", ~"c-dependencies", ~"pkg.rs"]);
let target = dir.join_many([~"src", ~"cdep-0.1", ~"pkg.rs"]); let target = dir.join_many([~"src", ~"cdep-0.1", ~"pkg.rs"]);
debug!("Copying {} -> {}", source.display(), target.display()); debug!("Copying {} -> {}", source.display(), target.display());
if !os::copy_file(&source, &target) { file::copy(&source, &target);
fail!("Couldn't copy file");
}
command_line_test([~"build", ~"cdep"], dir); command_line_test([~"build", ~"cdep"], dir);
assert_executable_exists(dir, "cdep"); assert_executable_exists(dir, "cdep");
let out_dir = target_build_dir(dir).join("cdep"); let out_dir = target_build_dir(dir).join("cdep");
let c_library_path = out_dir.join(platform_library_name("foo")); let c_library_path = out_dir.join(platform_library_name("foo"));
debug!("c library path: {}", c_library_path.display()); debug!("c library path: {}", c_library_path.display());
assert!(os::path_exists(&c_library_path)); assert!(c_library_path.exists());
// Now, make the Rust library read-only so rebuilding will fail // Now, make the Rust library read-only so rebuilding will fail
match built_library_in_workspace(&PkgId::new("cdep"), dir) { match built_library_in_workspace(&PkgId::new("cdep"), dir) {
@ -2380,8 +2368,5 @@ fn test_c_dependency_yes_rebuilding() {
fn is_executable(p: &Path) -> bool { fn is_executable(p: &Path) -> bool {
use std::libc::consts::os::posix88::{S_IXUSR}; use std::libc::consts::os::posix88::{S_IXUSR};
match p.get_mode() { p.exists() && p.stat().mode & S_IXUSR as u64 == S_IXUSR as u64
None => false,
Some(mode) => mode & S_IXUSR as uint == S_IXUSR as uint
}
} }

View file

@ -31,7 +31,7 @@ pub fn main() {
let sysroot_arg = args[1].clone(); let sysroot_arg = args[1].clone();
let sysroot = Path::new(sysroot_arg); let sysroot = Path::new(sysroot_arg);
if !os::path_exists(&sysroot) { if !sysroot.exists() {
fail!("Package script requires a sysroot that exists; {} doesn't", sysroot.display()); fail!("Package script requires a sysroot that exists; {} doesn't", sysroot.display());
} }

View file

@ -12,9 +12,7 @@ extern mod rustpkg;
extern mod rustc; extern mod rustc;
use std::os; use std::os;
use std::rt::io; use std::rt::io::file;
use std::rt::io::Writer;
use std::rt::io::file::FileInfo;
use rustpkg::api; use rustpkg::api;
use rustpkg::version::NoVersion; use rustpkg::version::NoVersion;
@ -30,7 +28,7 @@ pub fn main() {
let sysroot_arg = args[1].clone(); let sysroot_arg = args[1].clone();
let sysroot = Path::new(sysroot_arg); let sysroot = Path::new(sysroot_arg);
if !os::path_exists(&sysroot) { if !sysroot.exists() {
debug!("Failing, sysroot"); debug!("Failing, sysroot");
fail!("Package script requires a sysroot that exists;{} doesn't", sysroot.display()); fail!("Package script requires a sysroot that exists;{} doesn't", sysroot.display());
} }
@ -45,7 +43,7 @@ pub fn main() {
let out_path = os::self_exe_path().expect("Couldn't get self_exe path"); let out_path = os::self_exe_path().expect("Couldn't get self_exe path");
debug!("Writing file"); debug!("Writing file");
let mut file = out_path.join("generated.rs").open_writer(io::Create); let mut file = file::create(&out_path.join("generated.rs"));
file.write("pub fn wheeeee() { let xs = [1, 2, 3]; \ file.write("pub fn wheeeee() { let xs = [1, 2, 3]; \
for _ in xs.iter() { assert!(true); } }".as_bytes()); for _ in xs.iter() { assert!(true); } }".as_bytes());

View file

@ -10,6 +10,8 @@
use std::libc; use std::libc;
use std::os; use std::os;
use std::rt::io;
use std::rt::io::file;
use extra::workcache; use extra::workcache;
use rustc::driver::{driver, session}; use rustc::driver::{driver, session};
use extra::getopts::groups::getopts; use extra::getopts::groups::getopts;
@ -32,7 +34,6 @@ use path_util::{default_workspace, built_library_in_workspace};
pub use target::{OutputType, Main, Lib, Bench, Test, JustOne, lib_name_of, lib_crate_filename}; pub use target::{OutputType, Main, Lib, Bench, Test, JustOne, lib_name_of, lib_crate_filename};
pub use target::{Target, Build, Install}; pub use target::{Target, Build, Install};
use extra::treemap::TreeMap; use extra::treemap::TreeMap;
use path_util::U_RWX;
pub use target::{lib_name_of, lib_crate_filename, WhatToBuild, MaybeCustom, Inferred}; pub use target::{lib_name_of, lib_crate_filename, WhatToBuild, MaybeCustom, Inferred};
use workcache_support::{digest_file_with_date, digest_only_date}; use workcache_support::{digest_file_with_date, digest_only_date};
@ -184,7 +185,7 @@ pub fn compile_input(context: &BuildContext,
let mut out_dir = target_build_dir(workspace); let mut out_dir = target_build_dir(workspace);
out_dir.push(&pkg_id.path); out_dir.push(&pkg_id.path);
// Make the output directory if it doesn't exist already // Make the output directory if it doesn't exist already
assert!(os::mkdir_recursive(&out_dir, U_RWX)); file::mkdir_recursive(&out_dir, io::UserRWX);
let binary = os::args()[0].to_managed(); let binary = os::args()[0].to_managed();
@ -256,11 +257,11 @@ pub fn compile_input(context: &BuildContext,
// Make sure all the library directories actually exist, since the linker will complain // Make sure all the library directories actually exist, since the linker will complain
// otherwise // otherwise
for p in addl_lib_search_paths.iter() { for p in addl_lib_search_paths.iter() {
if os::path_exists(p) { if p.exists() {
assert!(os::path_is_dir(p)); assert!(p.is_dir())
} }
else { else {
assert!(os::mkdir_recursive(p, U_RWX)); file::mkdir_recursive(p, io::UserRWX);
} }
} }
@ -324,7 +325,7 @@ pub fn compile_input(context: &BuildContext,
}; };
for p in discovered_output.iter() { for p in discovered_output.iter() {
debug!("About to discover output {}", p.display()); debug!("About to discover output {}", p.display());
if os::path_exists(p) { if p.exists() {
debug!("4. discovering output {}", p.display()); debug!("4. discovering output {}", p.display());
// FIXME (#9639): This needs to handle non-utf8 paths // FIXME (#9639): This needs to handle non-utf8 paths
exec.discover_output("binary", p.as_str().unwrap(), digest_only_date(p)); exec.discover_output("binary", p.as_str().unwrap(), digest_only_date(p));
@ -629,10 +630,16 @@ fn debug_flags() -> ~[~str] { ~[] }
/// Returns the last-modified date as an Option /// Returns the last-modified date as an Option
pub fn datestamp(p: &Path) -> Option<libc::time_t> { pub fn datestamp(p: &Path) -> Option<libc::time_t> {
debug!("Scrutinizing datestamp for {} - does it exist? {:?}", p.display(), os::path_exists(p)); debug!("Scrutinizing datestamp for {} - does it exist? {:?}", p.display(),
let out = p.stat().map(|stat| stat.modified); p.exists());
debug!("Date = {:?}", out); match io::result(|| p.stat()) {
out.map(|t| { t as libc::time_t }) Ok(s) => {
let out = s.modified;
debug!("Date = {:?}", out);
Some(out as libc::time_t)
}
Err(*) => None,
}
} }
pub type DepMap = TreeMap<~str, ~[(~str, ~str)]>; pub type DepMap = TreeMap<~str, ~[(~str, ~str)]>;

View file

@ -14,7 +14,7 @@
extern mod std; extern mod std;
use extra::semver; use extra::semver;
use std::{char, os, result, run, str}; use std::{char, result, run, str};
use extra::tempfile::TempDir; use extra::tempfile::TempDir;
use path_util::rust_path; use path_util::rust_path;
@ -100,7 +100,7 @@ pub fn try_getting_local_version(local_path: &Path) -> Option<Version> {
for rp in rustpath.iter() { for rp in rustpath.iter() {
let local_path = rp.join(local_path); let local_path = rp.join(local_path);
let git_dir = local_path.join(".git"); let git_dir = local_path.join(".git");
if !os::path_is_dir(&git_dir) { if !git_dir.is_dir() {
continue; continue;
} }
// FIXME (#9639): This needs to handle non-utf8 paths // FIXME (#9639): This needs to handle non-utf8 paths

View file

@ -9,32 +9,23 @@
// except according to those terms. // except according to those terms.
use std::rt::io; use std::rt::io;
use std::rt::io::Reader; use std::rt::io::file;
use std::rt::io::file::FileInfo;
use extra::workcache; use extra::workcache;
use sha1::{Digest, Sha1}; use sha1::{Digest, Sha1};
/// Hashes the file contents along with the last-modified time /// Hashes the file contents along with the last-modified time
pub fn digest_file_with_date(path: &Path) -> ~str { pub fn digest_file_with_date(path: &Path) -> ~str {
use conditions::bad_path::cond; use conditions::bad_path::cond;
use cond1 = conditions::bad_stat::cond;
let mut err = None; match io::result(|| file::open(path).read_to_end()) {
let bytes = do io::io_error::cond.trap(|e| err = Some(e)).inside { Ok(bytes) => {
path.open_reader(io::Open).read_to_end()
};
match err {
None => {
let mut sha = Sha1::new(); let mut sha = Sha1::new();
sha.input(bytes); sha.input(bytes);
let st = match path.stat() { let st = path.stat();
Some(st) => st,
None => cond1.raise((path.clone(), format!("Couldn't get file access time")))
};
sha.input_str(st.modified.to_str()); sha.input_str(st.modified.to_str());
sha.result_str() sha.result_str()
} }
Some(e) => { Err(e) => {
cond.raise((path.clone(), format!("Couldn't read file: {}", e.desc))); cond.raise((path.clone(), format!("Couldn't read file: {}", e.desc)));
~"" ~""
} }
@ -43,13 +34,8 @@ pub fn digest_file_with_date(path: &Path) -> ~str {
/// Hashes only the last-modified time /// Hashes only the last-modified time
pub fn digest_only_date(path: &Path) -> ~str { pub fn digest_only_date(path: &Path) -> ~str {
use cond = conditions::bad_stat::cond;
let mut sha = Sha1::new(); let mut sha = Sha1::new();
let st = match path.stat() { let st = path.stat();
Some(st) => st,
None => cond.raise((path.clone(), format!("Couldn't get file access time")))
};
sha.input_str(st.modified.to_str()); sha.input_str(st.modified.to_str());
sha.result_str() sha.result_str()
} }

View file

@ -52,7 +52,7 @@ pub fn pkg_parent_workspaces(cx: &Context, pkgid: &PkgId) -> ~[Path] {
} }
pub fn is_workspace(p: &Path) -> bool { pub fn is_workspace(p: &Path) -> bool {
os::path_is_dir(&p.join("src")) p.join("src").is_dir()
} }
/// Construct a workspace and package-ID name based on the current directory. /// Construct a workspace and package-ID name based on the current directory.

View file

@ -182,7 +182,7 @@ impl FsRequest {
self.sync_cleanup(result) self.sync_cleanup(result)
} }
pub fn mkdir(self, loop_: &Loop, path: &CString, mode: int, cb: FsCallback) { pub fn mkdir(self, loop_: &Loop, path: &CString, mode: c_int, cb: FsCallback) {
let complete_cb_ptr = { let complete_cb_ptr = {
let mut me = self; let mut me = self;
me.req_boilerplate(Some(cb)) me.req_boilerplate(Some(cb))
@ -221,6 +221,18 @@ impl FsRequest {
assert_eq!(ret, 0); assert_eq!(ret, 0);
} }
pub fn chmod(self, loop_: &Loop, path: &CString, mode: c_int, cb: FsCallback) {
let complete_cb_ptr = {
let mut me = self;
me.req_boilerplate(Some(cb))
};
let ret = path.with_ref(|p| unsafe {
uvll::fs_chmod(loop_.native_handle(), self.native_handle(), p, mode,
complete_cb_ptr)
});
assert_eq!(ret, 0);
}
pub fn readdir(self, loop_: &Loop, path: &CString, pub fn readdir(self, loop_: &Loop, path: &CString,
flags: c_int, cb: FsCallback) { flags: c_int, cb: FsCallback) {
let complete_cb_ptr = { let complete_cb_ptr = {
@ -593,7 +605,7 @@ mod test {
S_IRUSR; S_IRUSR;
let mkdir_req = FsRequest::new(); let mkdir_req = FsRequest::new();
do mkdir_req.mkdir(&loop_, &path.to_c_str(), do mkdir_req.mkdir(&loop_, &path.to_c_str(),
mode as int) |req,uverr| { mode as c_int) |req,uverr| {
assert!(uverr.is_none()); assert!(uverr.is_none());
let loop_ = req.get_loop(); let loop_ = req.get_loop();
let stat_req = FsRequest::new(); let stat_req = FsRequest::new();
@ -626,12 +638,12 @@ mod test {
let mode = S_IWUSR | let mode = S_IWUSR |
S_IRUSR; S_IRUSR;
let mkdir_req = FsRequest::new(); let mkdir_req = FsRequest::new();
do mkdir_req.mkdir(&loop_, &path.to_c_str(), mode as int) |req,uverr| { do mkdir_req.mkdir(&loop_, &path.to_c_str(), mode as c_int) |req,uverr| {
assert!(uverr.is_none()); assert!(uverr.is_none());
let loop_ = req.get_loop(); let loop_ = req.get_loop();
let mkdir_req = FsRequest::new(); let mkdir_req = FsRequest::new();
do mkdir_req.mkdir(&loop_, &path.to_c_str(), do mkdir_req.mkdir(&loop_, &path.to_c_str(),
mode as int) |req,uverr| { mode as c_int) |req,uverr| {
assert!(uverr.is_some()); assert!(uverr.is_some());
let loop_ = req.get_loop(); let loop_ = req.get_loop();
let _stat = req.get_stat(); let _stat = req.get_stat();

View file

@ -20,6 +20,7 @@ use std::option::*;
use std::ptr; use std::ptr;
use std::str; use std::str;
use std::result::*; use std::result::*;
use std::rt::io;
use std::rt::io::IoError; use std::rt::io::IoError;
use std::rt::io::net::ip::{SocketAddr, IpAddr}; use std::rt::io::net::ip::{SocketAddr, IpAddr};
use std::rt::io::{standard_error, OtherIoError, SeekStyle, SeekSet, SeekCur, use std::rt::io::{standard_error, OtherIoError, SeekStyle, SeekSet, SeekCur,
@ -34,7 +35,7 @@ use std::rt::task::Task;
use std::unstable::sync::Exclusive; use std::unstable::sync::Exclusive;
use std::path::{GenericPath, Path}; use std::path::{GenericPath, Path};
use std::libc::{lseek, off_t, O_CREAT, O_APPEND, O_TRUNC, O_RDWR, O_RDONLY, use std::libc::{lseek, off_t, O_CREAT, O_APPEND, O_TRUNC, O_RDWR, O_RDONLY,
O_WRONLY, S_IRUSR, S_IWUSR, S_IRWXU}; O_WRONLY, S_IRUSR, S_IWUSR};
use std::rt::io::{FileMode, FileAccess, OpenOrCreate, Open, Create, use std::rt::io::{FileMode, FileAccess, OpenOrCreate, Open, Create,
CreateOrTruncate, Append, Truncate, Read, Write, ReadWrite, CreateOrTruncate, Append, Truncate, Read, Write, ReadWrite,
FileStat}; FileStat};
@ -699,9 +700,10 @@ impl IoFactory for UvIoFactory {
assert!(!result_cell.is_empty()); assert!(!result_cell.is_empty());
return result_cell.take(); return result_cell.take();
} }
fn fs_mkdir(&mut self, path: &CString, mode: int) -> Result<(), IoError> { fn fs_mkdir(&mut self, path: &CString,
perm: io::FilePermission) -> Result<(), IoError> {
do uv_fs_helper(self.uv_loop(), path) |mkdir_req, l, p, cb| { do uv_fs_helper(self.uv_loop(), path) |mkdir_req, l, p, cb| {
do mkdir_req.mkdir(l, p, mode) |req, err| { do mkdir_req.mkdir(l, p, perm as c_int) |req, err| {
cb(req, err) cb(req, err)
}; };
} }
@ -722,6 +724,15 @@ impl IoFactory for UvIoFactory {
}; };
} }
} }
fn fs_chmod(&mut self, path: &CString,
perm: io::FilePermission) -> Result<(), IoError> {
do uv_fs_helper(self.uv_loop(), path) |chmod_req, l, p, cb| {
do chmod_req.chmod(l, p, perm as c_int) |req, err| {
cb(req, err)
};
}
}
>>>>>>> Remove all blocking std::os blocking functions
fn fs_readdir(&mut self, path: &CString, flags: c_int) -> fn fs_readdir(&mut self, path: &CString, flags: c_int) ->
Result<~[Path], IoError> { Result<~[Path], IoError> {
use str::StrSlice; use str::StrSlice;

View file

@ -795,8 +795,8 @@ pub unsafe fn fs_fstat(loop_ptr: *uv_loop_t, req: *uv_fs_t, fd: c_int, cb: *u8)
rust_uv_fs_fstat(loop_ptr, req, fd, cb) rust_uv_fs_fstat(loop_ptr, req, fd, cb)
} }
pub unsafe fn fs_mkdir(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char, mode: int, pub unsafe fn fs_mkdir(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char,
cb: *u8) -> c_int { mode: c_int, cb: *u8) -> c_int {
#[fixed_stack_segment]; #[inline(never)]; #[fixed_stack_segment]; #[inline(never)];
rust_uv_fs_mkdir(loop_ptr, req, path, mode as c_int, cb) rust_uv_fs_mkdir(loop_ptr, req, path, mode as c_int, cb)
@ -813,6 +813,12 @@ pub unsafe fn fs_rename(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char,
rust_uv_fs_rename(loop_ptr, req, path, to, cb) rust_uv_fs_rename(loop_ptr, req, path, to, cb)
} }
pub unsafe fn fs_chmod(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char,
mode: c_int, cb: *u8) -> c_int {
#[fixed_stack_segment]; #[inline(never)];
rust_uv_fs_chmod(loop_ptr, req, path, mode as c_int, cb)
}
pub unsafe fn fs_readdir(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char, pub unsafe fn fs_readdir(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char,
flags: c_int, cb: *u8) -> c_int { flags: c_int, cb: *u8) -> c_int {
#[fixed_stack_segment]; #[inline(never)]; #[fixed_stack_segment]; #[inline(never)];
@ -1115,6 +1121,8 @@ extern {
cb: *u8) -> c_int; cb: *u8) -> c_int;
fn rust_uv_fs_rename(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char, fn rust_uv_fs_rename(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char,
to: *c_char, cb: *u8) -> c_int; to: *c_char, cb: *u8) -> c_int;
fn rust_uv_fs_chmod(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char,
mode: c_int, cb: *u8) -> c_int;
fn rust_uv_fs_readdir(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char, fn rust_uv_fs_readdir(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char,
flags: c_int, cb: *u8) -> c_int; flags: c_int, cb: *u8) -> c_int;
fn rust_uv_fs_req_cleanup(req: *uv_fs_t); fn rust_uv_fs_req_cleanup(req: *uv_fs_t);

View file

@ -317,8 +317,11 @@ impl Zero for bool {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use cmp::{Equal, Greater, Less, Eq, TotalOrd};
use prelude::*; use ops::{BitAnd, BitXor, BitOr};
use from_str::{FromStr, from_str};
use option::{Some, None};
use super::all_values;
#[test] #[test]
fn test_bool() { fn test_bool() {

View file

@ -35,7 +35,6 @@ use container::Container;
use iter::range; use iter::range;
use libc; use libc;
use libc::{c_char, c_void, c_int, size_t}; use libc::{c_char, c_void, c_int, size_t};
use libc::FILE;
use option::{Some, None}; use option::{Some, None};
use os; use os;
use prelude::*; use prelude::*;
@ -45,7 +44,6 @@ use to_str;
use unstable::finally::Finally; use unstable::finally::Finally;
use vec; use vec;
pub use libc::fclose;
pub use os::consts::*; pub use os::consts::*;
/// Delegates to the libc close() function, returning the same return value. /// Delegates to the libc close() function, returning the same return value.
@ -56,28 +54,6 @@ pub fn close(fd: c_int) -> c_int {
} }
} }
// On Windows, wide character version of function must be used to support
// unicode, so functions should be split into at least two versions,
// which are for Windows and for non-Windows, if necessary.
// See https://github.com/mozilla/rust/issues/9822 for more information.
mod rustrt {
use libc::{c_char, c_int};
use libc;
extern {
pub fn rust_path_is_dir(path: *libc::c_char) -> c_int;
pub fn rust_path_exists(path: *libc::c_char) -> c_int;
}
// Uses _wstat instead of stat.
#[cfg(windows)]
extern {
pub fn rust_path_is_dir_u16(path: *u16) -> c_int;
pub fn rust_path_exists_u16(path: *u16) -> c_int;
}
}
pub static TMPBUF_SZ : uint = 1000u; pub static TMPBUF_SZ : uint = 1000u;
static BUF_BYTES : uint = 2048u; static BUF_BYTES : uint = 2048u;
@ -348,15 +324,6 @@ pub fn unsetenv(n: &str) {
_unsetenv(n); _unsetenv(n);
} }
pub fn fdopen(fd: c_int) -> *FILE {
#[fixed_stack_segment]; #[inline(never)];
do "r".with_c_str |modebuf| {
unsafe {
libc::fdopen(fd, modebuf)
}
}
}
pub struct Pipe { pub struct Pipe {
input: c_int, input: c_int,
out: c_int out: c_int
@ -373,8 +340,6 @@ pub fn pipe() -> Pipe {
} }
} }
#[cfg(windows)] #[cfg(windows)]
pub fn pipe() -> Pipe { pub fn pipe() -> Pipe {
#[fixed_stack_segment]; #[inline(never)]; #[fixed_stack_segment]; #[inline(never)];
@ -574,58 +539,6 @@ pub fn tmpdir() -> Path {
} }
} }
/// Recursively walk a directory structure
pub fn walk_dir(p: &Path, f: &fn(&Path) -> bool) -> bool {
let r = list_dir(p);
r.iter().advance(|q| {
let path = &p.join(q);
f(path) && (!path_is_dir(path) || walk_dir(path, |p| f(p)))
})
}
#[cfg(unix)]
/// Indicates whether a path represents a directory
pub fn path_is_dir(p: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
do p.with_c_str |buf| {
rustrt::rust_path_is_dir(buf) != 0 as c_int
}
}
}
#[cfg(windows)]
pub fn path_is_dir(p: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
do os::win32::as_utf16_p(p.as_str().unwrap()) |buf| {
rustrt::rust_path_is_dir_u16(buf) != 0 as c_int
}
}
}
#[cfg(unix)]
/// Indicates whether a path exists
pub fn path_exists(p: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
do p.with_c_str |buf| {
rustrt::rust_path_exists(buf) != 0 as c_int
}
}
}
#[cfg(windows)]
pub fn path_exists(p: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
do os::win32::as_utf16_p(p.as_str().unwrap()) |buf| {
rustrt::rust_path_exists_u16(buf) != 0 as c_int
}
}
}
/** /**
* Convert a relative path to an absolute path * Convert a relative path to an absolute path
* *
@ -646,206 +559,6 @@ pub fn make_absolute(p: &Path) -> Path {
} }
} }
/// Creates a directory at the specified path
pub fn make_dir(p: &Path, mode: c_int) -> bool {
return mkdir(p, mode);
#[cfg(windows)]
fn mkdir(p: &Path, _mode: c_int) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
use os::win32::as_utf16_p;
// FIXME: turn mode into something useful? #2623
do as_utf16_p(p.as_str().unwrap()) |buf| {
libc::CreateDirectoryW(buf, ptr::mut_null())
!= (0 as libc::BOOL)
}
}
}
#[cfg(unix)]
fn mkdir(p: &Path, mode: c_int) -> bool {
#[fixed_stack_segment]; #[inline(never)];
do p.with_c_str |buf| {
unsafe {
libc::mkdir(buf, mode as libc::mode_t) == (0 as c_int)
}
}
}
}
/// Creates a directory with a given mode.
/// Returns true iff creation
/// succeeded. Also creates all intermediate subdirectories
/// if they don't already exist, giving all of them the same mode.
// tjc: if directory exists but with different permissions,
// should we return false?
pub fn mkdir_recursive(p: &Path, mode: c_int) -> bool {
if path_is_dir(p) {
return true;
}
if p.filename().is_some() {
let mut p_ = p.clone();
p_.pop();
if !mkdir_recursive(&p_, mode) {
return false;
}
}
return make_dir(p, mode);
}
/// Lists the contents of a directory
///
/// Each resulting Path is a relative path with no directory component.
pub fn list_dir(p: &Path) -> ~[Path] {
unsafe {
#[cfg(target_os = "linux")]
#[cfg(target_os = "android")]
#[cfg(target_os = "freebsd")]
#[cfg(target_os = "macos")]
unsafe fn get_list(p: &Path) -> ~[Path] {
#[fixed_stack_segment]; #[inline(never)];
use libc::{dirent_t};
use libc::{opendir, readdir, closedir};
extern {
fn rust_list_dir_val(ptr: *dirent_t) -> *libc::c_char;
}
let mut paths = ~[];
debug!("os::list_dir -- BEFORE OPENDIR");
let dir_ptr = do p.with_c_str |buf| {
opendir(buf)
};
if (dir_ptr as uint != 0) {
debug!("os::list_dir -- opendir() SUCCESS");
let mut entry_ptr = readdir(dir_ptr);
while (entry_ptr as uint != 0) {
let cstr = CString::new(rust_list_dir_val(entry_ptr), false);
paths.push(Path::new(cstr));
entry_ptr = readdir(dir_ptr);
}
closedir(dir_ptr);
}
else {
debug!("os::list_dir -- opendir() FAILURE");
}
debug!("os::list_dir -- AFTER -- \\#: {}", paths.len());
paths
}
#[cfg(windows)]
unsafe fn get_list(p: &Path) -> ~[Path] {
#[fixed_stack_segment]; #[inline(never)];
use libc::consts::os::extra::INVALID_HANDLE_VALUE;
use libc::{wcslen, free};
use libc::funcs::extra::kernel32::{
FindFirstFileW,
FindNextFileW,
FindClose,
};
use libc::types::os::arch::extra::HANDLE;
use os::win32::{
as_utf16_p
};
use rt::global_heap::malloc_raw;
#[nolink]
extern {
fn rust_list_dir_wfd_size() -> libc::size_t;
fn rust_list_dir_wfd_fp_buf(wfd: *libc::c_void) -> *u16;
}
let star = p.join("*");
do as_utf16_p(star.as_str().unwrap()) |path_ptr| {
let mut paths = ~[];
let wfd_ptr = malloc_raw(rust_list_dir_wfd_size() as uint);
let find_handle = FindFirstFileW(path_ptr, wfd_ptr as HANDLE);
if find_handle as libc::c_int != INVALID_HANDLE_VALUE {
let mut more_files = 1 as libc::c_int;
while more_files != 0 {
let fp_buf = rust_list_dir_wfd_fp_buf(wfd_ptr);
if fp_buf as uint == 0 {
fail!("os::list_dir() failure: got null ptr from wfd");
}
else {
let fp_vec = vec::from_buf(
fp_buf, wcslen(fp_buf) as uint);
let fp_str = str::from_utf16(fp_vec);
paths.push(Path::new(fp_str));
}
more_files = FindNextFileW(find_handle, wfd_ptr as HANDLE);
}
FindClose(find_handle);
free(wfd_ptr)
}
paths
}
}
do get_list(p).move_iter().filter |path| {
path.as_vec() != bytes!(".") && path.as_vec() != bytes!("..")
}.collect()
}
}
/**
* Lists the contents of a directory
*
* This version prepends each entry with the directory.
*/
pub fn list_dir_path(p: &Path) -> ~[Path] {
list_dir(p).map(|f| p.join(f))
}
/// Removes a directory at the specified path, after removing
/// all its contents. Use carefully!
pub fn remove_dir_recursive(p: &Path) -> bool {
let mut error_happened = false;
do walk_dir(p) |inner| {
if !error_happened {
if path_is_dir(inner) {
if !remove_dir_recursive(inner) {
error_happened = true;
}
}
else {
if !remove_file(inner) {
error_happened = true;
}
}
}
true
};
// Directory should now be empty
!error_happened && remove_dir(p)
}
/// Removes a directory at the specified path
pub fn remove_dir(p: &Path) -> bool {
return rmdir(p);
#[cfg(windows)]
fn rmdir(p: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
use os::win32::as_utf16_p;
return do as_utf16_p(p.as_str().unwrap()) |buf| {
libc::RemoveDirectoryW(buf) != (0 as libc::BOOL)
};
}
}
#[cfg(unix)]
fn rmdir(p: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
do p.with_c_str |buf| {
unsafe {
libc::rmdir(buf) == (0 as c_int)
}
}
}
}
/// Changes the current working directory to the specified path, returning /// Changes the current working directory to the specified path, returning
/// whether the change was completed successfully or not. /// whether the change was completed successfully or not.
pub fn change_dir(p: &Path) -> bool { pub fn change_dir(p: &Path) -> bool {
@ -873,121 +586,6 @@ pub fn change_dir(p: &Path) -> bool {
} }
} }
/// Copies a file from one location to another
pub fn copy_file(from: &Path, to: &Path) -> bool {
return do_copy_file(from, to);
#[cfg(windows)]
fn do_copy_file(from: &Path, to: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
use os::win32::as_utf16_p;
return do as_utf16_p(from.as_str().unwrap()) |fromp| {
do as_utf16_p(to.as_str().unwrap()) |top| {
libc::CopyFileW(fromp, top, (0 as libc::BOOL)) !=
(0 as libc::BOOL)
}
}
}
}
#[cfg(unix)]
fn do_copy_file(from: &Path, to: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
let istream = do from.with_c_str |fromp| {
do "rb".with_c_str |modebuf| {
libc::fopen(fromp, modebuf)
}
};
if istream as uint == 0u {
return false;
}
// Preserve permissions
let from_mode = from.get_mode().expect("copy_file: couldn't get permissions \
for source file");
let ostream = do to.with_c_str |top| {
do "w+b".with_c_str |modebuf| {
libc::fopen(top, modebuf)
}
};
if ostream as uint == 0u {
fclose(istream);
return false;
}
let bufsize = 8192u;
let mut buf = vec::with_capacity::<u8>(bufsize);
let mut done = false;
let mut ok = true;
while !done {
do buf.as_mut_buf |b, _sz| {
let nread = libc::fread(b as *mut c_void, 1u as size_t,
bufsize as size_t,
istream);
if nread > 0 as size_t {
if libc::fwrite(b as *c_void, 1u as size_t, nread,
ostream) != nread {
ok = false;
done = true;
}
} else {
done = true;
}
}
}
fclose(istream);
fclose(ostream);
// Give the new file the old file's permissions
if do to.with_c_str |to_buf| {
libc::chmod(to_buf, from_mode as libc::mode_t)
} != 0 {
return false; // should be a condition...
}
return ok;
}
}
}
/// Deletes an existing file
pub fn remove_file(p: &Path) -> bool {
return unlink(p);
#[cfg(windows)]
fn unlink(p: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
use os::win32::as_utf16_p;
return do as_utf16_p(p.as_str().unwrap()) |buf| {
libc::DeleteFileW(buf) != (0 as libc::BOOL)
};
}
}
#[cfg(unix)]
fn unlink(p: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
do p.with_c_str |buf| {
libc::unlink(buf) == (0 as c_int)
}
}
}
}
/// Renames an existing file or directory
pub fn rename_file(old: &Path, new: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
do old.with_c_str |old_buf| {
do new.with_c_str |new_buf| {
libc::rename(old_buf, new_buf) == (0 as c_int)
}
}
}
}
#[cfg(unix)] #[cfg(unix)]
/// Returns the platform-specific value of errno /// Returns the platform-specific value of errno
pub fn errno() -> int { pub fn errno() -> int {
@ -1707,19 +1305,15 @@ pub mod consts {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use c_str::ToCStr; use c_str::ToCStr;
use libc::{c_int, c_void, size_t};
use libc;
use option::Some; use option::Some;
use option; use option;
use os::{env, getcwd, getenv, make_absolute, args}; use os::{env, getcwd, getenv, make_absolute, args};
use os::{remove_file, setenv, unsetenv}; use os::{setenv, unsetenv};
use os; use os;
use path::Path; use path::Path;
use rand::Rng; use rand::Rng;
use rand; use rand;
use run;
use str::StrSlice; use str::StrSlice;
use libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
#[test] #[test]
@ -1875,144 +1469,6 @@ mod tests {
for s in olduserprofile.iter() { setenv("USERPROFILE", *s) } for s in olduserprofile.iter() { setenv("USERPROFILE", *s) }
} }
#[test]
fn tmpdir() {
let p = os::tmpdir();
let s = p.as_str();
assert!(s.is_some() && s.unwrap() != ".");
}
// Issue #712
#[test]
fn test_list_dir_no_invalid_memory_access() {
os::list_dir(&Path::new("."));
}
#[test]
fn list_dir() {
let dirs = os::list_dir(&Path::new("."));
// Just assuming that we've got some contents in the current directory
assert!(dirs.len() > 0u);
for dir in dirs.iter() {
debug!("{:?}", (*dir).clone());
}
}
#[test]
#[cfg(not(windows))]
fn list_dir_root() {
let dirs = os::list_dir(&Path::new("/"));
assert!(dirs.len() > 1);
}
#[test]
#[cfg(windows)]
fn list_dir_root() {
let dirs = os::list_dir(&Path::new("C:\\"));
assert!(dirs.len() > 1);
}
#[test]
fn path_is_dir() {
use rt::io::file::open;
use rt::io::{OpenOrCreate, Read};
assert!((os::path_is_dir(&Path::new("."))));
assert!((!os::path_is_dir(&Path::new("test/stdtest/fs.rs"))));
let mut dirpath = os::tmpdir();
dirpath.push(format!("rust-test-{}/test-\uac00\u4e00\u30fc\u4f60\u597d",
rand::random::<u32>())); // 가一ー你好
debug!("path_is_dir dirpath: {}", dirpath.display());
let mkdir_result = os::mkdir_recursive(&dirpath, (S_IRUSR | S_IWUSR | S_IXUSR) as i32);
debug!("path_is_dir mkdir_result: {}", mkdir_result);
assert!((os::path_is_dir(&dirpath)));
let mut filepath = dirpath;
filepath.push("unicode-file-\uac00\u4e00\u30fc\u4f60\u597d.rs");
debug!("path_is_dir filepath: {}", filepath.display());
open(&filepath, OpenOrCreate, Read); // ignore return; touch only
assert!((!os::path_is_dir(&filepath)));
assert!((!os::path_is_dir(&Path::new(
"test/unicode-bogus-dir-\uac00\u4e00\u30fc\u4f60\u597d"))));
}
#[test]
fn path_exists() {
assert!((os::path_exists(&Path::new("."))));
assert!((!os::path_exists(&Path::new(
"test/nonexistent-bogus-path"))));
let mut dirpath = os::tmpdir();
dirpath.push(format!("rust-test-{}/test-\uac01\u4e01\u30fc\u518d\u89c1",
rand::random::<u32>())); // 각丁ー再见
os::mkdir_recursive(&dirpath, (S_IRUSR | S_IWUSR | S_IXUSR) as i32);
assert!((os::path_exists(&dirpath)));
assert!((!os::path_exists(&Path::new(
"test/unicode-bogus-path-\uac01\u4e01\u30fc\u518d\u89c1"))));
}
#[test]
fn copy_file_does_not_exist() {
assert!(!os::copy_file(&Path::new("test/nonexistent-bogus-path"),
&Path::new("test/other-bogus-path")));
assert!(!os::path_exists(&Path::new("test/other-bogus-path")));
}
#[test]
fn copy_file_ok() {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
let tempdir = getcwd(); // would like to use $TMPDIR,
// doesn't seem to work on Linux
let input = tempdir.join("in.txt");
let out = tempdir.join("out.txt");
/* Write the temp input file */
let ostream = do input.with_c_str |fromp| {
do "w+b".with_c_str |modebuf| {
libc::fopen(fromp, modebuf)
}
};
assert!((ostream as uint != 0u));
let s = ~"hello";
do "hello".with_c_str |buf| {
let write_len = libc::fwrite(buf as *c_void,
1u as size_t,
(s.len() + 1u) as size_t,
ostream);
assert_eq!(write_len, (s.len() + 1) as size_t)
}
assert_eq!(libc::fclose(ostream), (0u as c_int));
let in_mode = input.get_mode();
let rs = os::copy_file(&input, &out);
if (!os::path_exists(&input)) {
fail!("{} doesn't exist", input.display());
}
assert!((rs));
// FIXME (#9639): This needs to handle non-utf8 paths
let rslt = run::process_status("diff", [input.as_str().unwrap().to_owned(),
out.as_str().unwrap().to_owned()]);
assert_eq!(rslt, 0);
assert_eq!(out.get_mode(), in_mode);
assert!((remove_file(&input)));
assert!((remove_file(&out)));
}
}
#[test]
fn recursive_mkdir_slash() {
let path = Path::new("/");
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
}
#[test] #[test]
fn memory_map_rw() { fn memory_map_rw() {
use result::{Ok, Err}; use result::{Ok, Err};
@ -2039,6 +1495,7 @@ mod tests {
use result::{Ok, Err}; use result::{Ok, Err};
use os::*; use os::*;
use libc::*; use libc::*;
use rt::io::file;
#[cfg(unix)] #[cfg(unix)]
#[fixed_stack_segment] #[fixed_stack_segment]
@ -2060,7 +1517,6 @@ mod tests {
let mut path = tmpdir(); let mut path = tmpdir();
path.push("mmap_file.tmp"); path.push("mmap_file.tmp");
let size = MemoryMap::granularity() * 2; let size = MemoryMap::granularity() * 2;
remove_file(&path);
let fd = unsafe { let fd = unsafe {
let fd = do path.with_c_str |path| { let fd = do path.with_c_str |path| {
@ -2088,6 +1544,7 @@ mod tests {
assert!(*chunk.data == 0xbe); assert!(*chunk.data == 0xbe);
close(fd); close(fd);
} }
file::unlink(&path);
} }
// More recursive_mkdir tests are in extra::tempfile // More recursive_mkdir tests are in extra::tempfile

View file

@ -24,9 +24,6 @@ use vec;
use vec::{CopyableVector, RSplitIterator, SplitIterator, Vector, VectorVector}; use vec::{CopyableVector, RSplitIterator, SplitIterator, Vector, VectorVector};
use super::{BytesContainer, GenericPath, GenericPathUnsafe}; use super::{BytesContainer, GenericPath, GenericPathUnsafe};
#[cfg(not(target_os = "win32"))]
use rt::io::{FileStat, file, io_error};
/// Iterator that yields successive components of a Path as &[u8] /// Iterator that yields successive components of a Path as &[u8]
pub type ComponentIter<'self> = SplitIterator<'self, u8>; pub type ComponentIter<'self> = SplitIterator<'self, u8>;
/// Iterator that yields components of a Path in reverse as &[u8] /// Iterator that yields components of a Path in reverse as &[u8]
@ -442,72 +439,6 @@ fn normalize_helper<'a>(v: &'a [u8], is_abs: bool) -> Option<~[&'a [u8]]> {
static dot_static: &'static [u8] = bytes!("."); static dot_static: &'static [u8] = bytes!(".");
static dot_dot_static: &'static [u8] = bytes!(".."); static dot_dot_static: &'static [u8] = bytes!("..");
// Stat support
#[cfg(not(target_os = "win32"))]
impl Path {
/// Calls stat() on the represented file and returns the resulting rt::io::FileStat
pub fn stat(&self) -> Option<FileStat> {
let mut file_stat: Option<FileStat> = None;
do io_error::cond.trap(|_| { /* Ignore error, will return None */ }).inside {
file_stat = file::stat(self);
}
file_stat
}
/// Returns whether the represented file exists
pub fn exists(&self) -> bool {
match self.stat() {
None => false,
Some(_) => true
}
}
/// Returns the filesize of the represented file
pub fn get_size(&self) -> Option<u64> {
match self.stat() {
None => None,
Some(st) => Some(st.size)
}
}
/// Returns the mode of the represented file
pub fn get_mode(&self) -> Option<uint> {
match self.stat() {
None => None,
Some(st) => Some(st.mode as uint)
}
}
}
#[cfg(target_os = "freebsd")]
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
impl Path {
/// Returns the atime of the represented file, as msecs
pub fn get_atime(&self) -> Option<u64> {
match self.stat() {
None => None,
Some(st) => Some(st.accessed)
}
}
/// Returns the mtime of the represented file, as msecs
pub fn get_mtime(&self) -> Option<u64> {
match self.stat() {
None => None,
Some(st) => Some(st.modified)
}
}
/// Returns the ctime of the represented file, as msecs
pub fn get_ctime(&self) -> Option<u64> {
match self.stat() {
None => None,
Some(st) => Some(st.created)
}
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View file

@ -13,11 +13,12 @@
use rand::Rng; use rand::Rng;
use ops::Drop; use ops::Drop;
use path::Path;
#[cfg(unix)] #[cfg(unix)]
use rand::reader::ReaderRng; use rand::reader::ReaderRng;
#[cfg(unix)] #[cfg(unix)]
use rt::io::{file, Open, Read}; use rt::io::file;
#[cfg(windows)] #[cfg(windows)]
use cast; use cast;
@ -40,7 +41,7 @@ type HCRYPTPROV = c_long;
/// This does not block. /// This does not block.
#[cfg(unix)] #[cfg(unix)]
pub struct OSRng { pub struct OSRng {
priv inner: ReaderRng<file::FileStream> priv inner: ReaderRng<file::FileReader>
} }
/// A random number generator that retrieves randomness straight from /// A random number generator that retrieves randomness straight from
/// the operating system. Platform sources: /// the operating system. Platform sources:
@ -60,7 +61,8 @@ impl OSRng {
/// Create a new `OSRng`. /// Create a new `OSRng`.
#[cfg(unix)] #[cfg(unix)]
pub fn new() -> OSRng { pub fn new() -> OSRng {
let reader = file::open(& &"/dev/urandom", Open, Read).expect("Error opening /dev/urandom"); let reader = file::open(&Path::new("/dev/urandom"));
let reader = reader.expect("Error opening /dev/urandom");
let reader_rng = ReaderRng::new(reader); let reader_rng = ReaderRng::new(reader);
OSRng { inner: reader_rng } OSRng { inner: reader_rng }

File diff suppressed because it is too large Load diff

View file

@ -244,9 +244,12 @@ Out of scope
use cast; use cast;
use int; use int;
use libc;
use path::Path; use path::Path;
use prelude::*;
use str::{StrSlice, OwnedStr}; use str::{StrSlice, OwnedStr};
use option::{Option, Some, None};
use result::{Ok, Err, Result};
use iter::Iterator;
use to_str::ToStr; use to_str::ToStr;
use uint; use uint;
use unstable::finally::Finally; use unstable::finally::Finally;
@ -418,6 +421,18 @@ pub fn ignore_io_error<T>(cb: &fn() -> T) -> T {
} }
} }
/// Helper for catching an I/O error and wrapping it in a Result object. The
/// return result will be the last I/O error that happened or the result of the
/// closure if no error occurred.
pub fn result<T>(cb: &fn() -> T) -> Result<T, IoError> {
let mut err = None;
let ret = io_error::cond.trap(|e| err = Some(e)).inside(cb);
match err {
Some(e) => Err(e),
None => Ok(ret),
}
}
pub trait Reader { pub trait Reader {
// Only two methods which need to get implemented for this trait // Only two methods which need to get implemented for this trait
@ -1137,3 +1152,7 @@ pub struct FileStat {
/// platform-dependent msecs /// platform-dependent msecs
accessed: u64, accessed: u64,
} }
// FIXME(#10131): this needs to get designed for real
pub type FilePermission = u32;
pub static UserRWX: FilePermission = libc::S_IRWXU as FilePermission;

View file

@ -297,3 +297,486 @@ mod tests {
} }
} }
} }
// n.b. these functions were all part of the old `std::os` module. There's lots
// of fun little nuances that were taken care of by these functions, but
// they are all thread-blocking versions that are no longer desired (we now
// use a non-blocking event loop implementation backed by libuv).
//
// In theory we will have a thread-blocking version of the event loop (if
// desired), so these functions may just need to get adapted to work in
// those situtations. For now, I'm leaving the code around so it doesn't
// get bitrotted instantaneously.
mod old_os {
use prelude::*;
use c_str::CString;
use libc::fclose;
use libc::{size_t, c_void, c_int};
use libc;
use vec;
#[cfg(test)] use os;
#[cfg(test)] use rand;
// On Windows, wide character version of function must be used to support
// unicode, so functions should be split into at least two versions,
// which are for Windows and for non-Windows, if necessary.
// See https://github.com/mozilla/rust/issues/9822 for more information.
mod rustrt {
use libc::{c_char, c_int};
use libc;
extern {
pub fn rust_path_is_dir(path: *libc::c_char) -> c_int;
pub fn rust_path_exists(path: *libc::c_char) -> c_int;
}
// Uses _wstat instead of stat.
#[cfg(windows)]
extern {
pub fn rust_path_is_dir_u16(path: *u16) -> c_int;
pub fn rust_path_exists_u16(path: *u16) -> c_int;
}
}
/// Recursively walk a directory structure
pub fn walk_dir(p: &Path, f: &fn(&Path) -> bool) -> bool {
let r = list_dir(p);
r.iter().advance(|q| {
let path = &p.join(q);
f(path) && (!path_is_dir(path) || walk_dir(path, |p| f(p)))
})
}
#[cfg(unix)]
/// Indicates whether a path represents a directory
pub fn path_is_dir(p: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
do p.with_c_str |buf| {
rustrt::rust_path_is_dir(buf) != 0 as c_int
}
}
}
#[cfg(windows)]
pub fn path_is_dir(p: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
do os::win32::as_utf16_p(p.as_str().unwrap()) |buf| {
rustrt::rust_path_is_dir_u16(buf) != 0 as c_int
}
}
}
#[cfg(unix)]
/// Indicates whether a path exists
pub fn path_exists(p: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
do p.with_c_str |buf| {
rustrt::rust_path_exists(buf) != 0 as c_int
}
}
}
#[cfg(windows)]
pub fn path_exists(p: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
do os::win32::as_utf16_p(p.as_str().unwrap()) |buf| {
rustrt::rust_path_exists_u16(buf) != 0 as c_int
}
}
}
/// Creates a directory at the specified path
pub fn make_dir(p: &Path, mode: c_int) -> bool {
return mkdir(p, mode);
#[cfg(windows)]
fn mkdir(p: &Path, _mode: c_int) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
use os::win32::as_utf16_p;
// FIXME: turn mode into something useful? #2623
do as_utf16_p(p.as_str().unwrap()) |buf| {
libc::CreateDirectoryW(buf, ptr::mut_null())
!= (0 as libc::BOOL)
}
}
}
#[cfg(unix)]
fn mkdir(p: &Path, mode: c_int) -> bool {
#[fixed_stack_segment]; #[inline(never)];
do p.with_c_str |buf| {
unsafe {
libc::mkdir(buf, mode as libc::mode_t) == (0 as c_int)
}
}
}
}
/// Creates a directory with a given mode.
/// Returns true iff creation
/// succeeded. Also creates all intermediate subdirectories
/// if they don't already exist, giving all of them the same mode.
// tjc: if directory exists but with different permissions,
// should we return false?
pub fn mkdir_recursive(p: &Path, mode: c_int) -> bool {
if path_is_dir(p) {
return true;
}
if p.filename().is_some() {
let mut p_ = p.clone();
p_.pop();
if !mkdir_recursive(&p_, mode) {
return false;
}
}
return make_dir(p, mode);
}
/// Lists the contents of a directory
///
/// Each resulting Path is a relative path with no directory component.
pub fn list_dir(p: &Path) -> ~[Path] {
unsafe {
#[cfg(target_os = "linux")]
#[cfg(target_os = "android")]
#[cfg(target_os = "freebsd")]
#[cfg(target_os = "macos")]
unsafe fn get_list(p: &Path) -> ~[Path] {
#[fixed_stack_segment]; #[inline(never)];
use libc::{dirent_t};
use libc::{opendir, readdir, closedir};
extern {
fn rust_list_dir_val(ptr: *dirent_t) -> *libc::c_char;
}
let mut paths = ~[];
debug!("os::list_dir -- BEFORE OPENDIR");
let dir_ptr = do p.with_c_str |buf| {
opendir(buf)
};
if (dir_ptr as uint != 0) {
debug!("os::list_dir -- opendir() SUCCESS");
let mut entry_ptr = readdir(dir_ptr);
while (entry_ptr as uint != 0) {
let cstr = CString::new(rust_list_dir_val(entry_ptr), false);
paths.push(Path::new(cstr));
entry_ptr = readdir(dir_ptr);
}
closedir(dir_ptr);
}
else {
debug!("os::list_dir -- opendir() FAILURE");
}
debug!("os::list_dir -- AFTER -- \\#: {}", paths.len());
paths
}
#[cfg(windows)]
unsafe fn get_list(p: &Path) -> ~[Path] {
#[fixed_stack_segment]; #[inline(never)];
use libc::consts::os::extra::INVALID_HANDLE_VALUE;
use libc::{wcslen, free};
use libc::funcs::extra::kernel32::{
FindFirstFileW,
FindNextFileW,
FindClose,
};
use libc::types::os::arch::extra::HANDLE;
use os::win32::{
as_utf16_p
};
use rt::global_heap::malloc_raw;
#[nolink]
extern {
fn rust_list_dir_wfd_size() -> libc::size_t;
fn rust_list_dir_wfd_fp_buf(wfd: *libc::c_void) -> *u16;
}
let star = p.join("*");
do as_utf16_p(star.as_str().unwrap()) |path_ptr| {
let mut paths = ~[];
let wfd_ptr = malloc_raw(rust_list_dir_wfd_size() as uint);
let find_handle = FindFirstFileW(path_ptr, wfd_ptr as HANDLE);
if find_handle as libc::c_int != INVALID_HANDLE_VALUE {
let mut more_files = 1 as libc::c_int;
while more_files != 0 {
let fp_buf = rust_list_dir_wfd_fp_buf(wfd_ptr);
if fp_buf as uint == 0 {
fail!("os::list_dir() failure: got null ptr from wfd");
}
else {
let fp_vec = vec::from_buf(
fp_buf, wcslen(fp_buf) as uint);
let fp_str = str::from_utf16(fp_vec);
paths.push(Path::new(fp_str));
}
more_files = FindNextFileW(find_handle, wfd_ptr as HANDLE);
}
FindClose(find_handle);
free(wfd_ptr)
}
paths
}
}
do get_list(p).move_iter().filter |path| {
path.as_vec() != bytes!(".") && path.as_vec() != bytes!("..")
}.collect()
}
}
/// Removes a directory at the specified path, after removing
/// all its contents. Use carefully!
pub fn remove_dir_recursive(p: &Path) -> bool {
let mut error_happened = false;
do walk_dir(p) |inner| {
if !error_happened {
if path_is_dir(inner) {
if !remove_dir_recursive(inner) {
error_happened = true;
}
}
else {
if !remove_file(inner) {
error_happened = true;
}
}
}
true
};
// Directory should now be empty
!error_happened && remove_dir(p)
}
/// Removes a directory at the specified path
pub fn remove_dir(p: &Path) -> bool {
return rmdir(p);
#[cfg(windows)]
fn rmdir(p: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
use os::win32::as_utf16_p;
return do as_utf16_p(p.as_str().unwrap()) |buf| {
libc::RemoveDirectoryW(buf) != (0 as libc::BOOL)
};
}
}
#[cfg(unix)]
fn rmdir(p: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
do p.with_c_str |buf| {
unsafe {
libc::rmdir(buf) == (0 as c_int)
}
}
}
}
/// Deletes an existing file
pub fn remove_file(p: &Path) -> bool {
return unlink(p);
#[cfg(windows)]
fn unlink(p: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
use os::win32::as_utf16_p;
return do as_utf16_p(p.as_str().unwrap()) |buf| {
libc::DeleteFileW(buf) != (0 as libc::BOOL)
};
}
}
#[cfg(unix)]
fn unlink(p: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
do p.with_c_str |buf| {
libc::unlink(buf) == (0 as c_int)
}
}
}
}
/// Renames an existing file or directory
pub fn rename_file(old: &Path, new: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
do old.with_c_str |old_buf| {
do new.with_c_str |new_buf| {
libc::rename(old_buf, new_buf) == (0 as c_int)
}
}
}
}
/// Copies a file from one location to another
pub fn copy_file(from: &Path, to: &Path) -> bool {
return do_copy_file(from, to);
#[cfg(windows)]
fn do_copy_file(from: &Path, to: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
use os::win32::as_utf16_p;
return do as_utf16_p(from.as_str().unwrap()) |fromp| {
do as_utf16_p(to.as_str().unwrap()) |top| {
libc::CopyFileW(fromp, top, (0 as libc::BOOL)) !=
(0 as libc::BOOL)
}
}
}
}
#[cfg(unix)]
fn do_copy_file(from: &Path, to: &Path) -> bool {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
let istream = do from.with_c_str |fromp| {
do "rb".with_c_str |modebuf| {
libc::fopen(fromp, modebuf)
}
};
if istream as uint == 0u {
return false;
}
// Preserve permissions
let from_mode = from.stat().mode;
let ostream = do to.with_c_str |top| {
do "w+b".with_c_str |modebuf| {
libc::fopen(top, modebuf)
}
};
if ostream as uint == 0u {
fclose(istream);
return false;
}
let bufsize = 8192u;
let mut buf = vec::with_capacity::<u8>(bufsize);
let mut done = false;
let mut ok = true;
while !done {
do buf.as_mut_buf |b, _sz| {
let nread = libc::fread(b as *mut c_void, 1u as size_t,
bufsize as size_t,
istream);
if nread > 0 as size_t {
if libc::fwrite(b as *c_void, 1u as size_t, nread,
ostream) != nread {
ok = false;
done = true;
}
} else {
done = true;
}
}
}
fclose(istream);
fclose(ostream);
// Give the new file the old file's permissions
if do to.with_c_str |to_buf| {
libc::chmod(to_buf, from_mode as libc::mode_t)
} != 0 {
return false; // should be a condition...
}
return ok;
}
}
}
#[test]
fn tmpdir() {
let p = os::tmpdir();
let s = p.as_str();
assert!(s.is_some() && s.unwrap() != ".");
}
// Issue #712
#[test]
fn test_list_dir_no_invalid_memory_access() {
list_dir(&Path::new("."));
}
#[test]
fn test_list_dir() {
let dirs = list_dir(&Path::new("."));
// Just assuming that we've got some contents in the current directory
assert!(dirs.len() > 0u);
for dir in dirs.iter() {
debug!("{:?}", (*dir).clone());
}
}
#[test]
#[cfg(not(windows))]
fn test_list_dir_root() {
let dirs = list_dir(&Path::new("/"));
assert!(dirs.len() > 1);
}
#[test]
#[cfg(windows)]
fn test_list_dir_root() {
let dirs = list_dir(&Path::new("C:\\"));
assert!(dirs.len() > 1);
}
#[test]
fn test_path_is_dir() {
use rt::io::file::{open_stream, mkdir_recursive};
use rt::io::{OpenOrCreate, Read, UserRWX};
assert!((path_is_dir(&Path::new("."))));
assert!((!path_is_dir(&Path::new("test/stdtest/fs.rs"))));
let mut dirpath = os::tmpdir();
dirpath.push(format!("rust-test-{}/test-\uac00\u4e00\u30fc\u4f60\u597d",
rand::random::<u32>())); // 가一ー你好
debug!("path_is_dir dirpath: {}", dirpath.display());
mkdir_recursive(&dirpath, UserRWX);
assert!((path_is_dir(&dirpath)));
let mut filepath = dirpath;
filepath.push("unicode-file-\uac00\u4e00\u30fc\u4f60\u597d.rs");
debug!("path_is_dir filepath: {}", filepath.display());
open_stream(&filepath, OpenOrCreate, Read); // ignore return; touch only
assert!((!path_is_dir(&filepath)));
assert!((!path_is_dir(&Path::new(
"test/unicode-bogus-dir-\uac00\u4e00\u30fc\u4f60\u597d"))));
}
#[test]
fn test_path_exists() {
use rt::io::file::mkdir_recursive;
use rt::io::UserRWX;
assert!((path_exists(&Path::new("."))));
assert!((!path_exists(&Path::new(
"test/nonexistent-bogus-path"))));
let mut dirpath = os::tmpdir();
dirpath.push(format!("rust-test-{}/test-\uac01\u4e01\u30fc\u518d\u89c1",
rand::random::<u32>())); // 각丁ー再见
mkdir_recursive(&dirpath, UserRWX);
assert!((path_exists(&dirpath)));
assert!((!path_exists(&Path::new(
"test/unicode-bogus-path-\uac01\u4e01\u30fc\u518d\u89c1"))));
}
}

View file

@ -156,7 +156,6 @@ mod tests {
use rt::test::*; use rt::test::*;
use rt::io::*; use rt::io::*;
use rt::comm::oneshot; use rt::comm::oneshot;
use os;
fn smalltest(server: ~fn(UnixStream), client: ~fn(UnixStream)) { fn smalltest(server: ~fn(UnixStream), client: ~fn(UnixStream)) {
let server = Cell::new(server); let server = Cell::new(server);
@ -290,7 +289,7 @@ mod tests {
do run_in_mt_newsched_task { do run_in_mt_newsched_task {
let path = next_test_unix(); let path = next_test_unix();
let _acceptor = UnixListener::bind(&path).listen(); let _acceptor = UnixListener::bind(&path).listen();
assert!(os::path_exists(&path)); assert!(path.exists());
} }
} }
} }

View file

@ -19,6 +19,7 @@ definitions for a number of signals.
*/ */
use container::{Map, MutableMap};
use comm::{Port, SharedChan, stream}; use comm::{Port, SharedChan, stream};
use hashmap; use hashmap;
use option::{Some, None}; use option::{Some, None};
@ -146,10 +147,10 @@ impl Listener {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*;
use libc; use libc;
use rt::io::timer; use rt::io::timer;
use super::{Listener, Interrupt};
use comm::{GenericPort, Peekable};
// kill is only available on Unixes // kill is only available on Unixes
#[cfg(unix)] #[cfg(unix)]
@ -207,7 +208,7 @@ mod test {
#[cfg(windows)] #[cfg(windows)]
#[test] #[test]
fn test_io_signal_invalid_signum() { fn test_io_signal_invalid_signum() {
use rt::io; use super::User1;
let mut s = Listener::new(); let mut s = Listener::new();
let mut called = false; let mut called = false;
do io::io_error::cond.trap(|_| { do io::io_error::cond.trap(|_| {

View file

@ -108,6 +108,7 @@ impl Timer {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use prelude::*;
use super::*; use super::*;
use rt::test::*; use rt::test::*;
use cell::Cell; use cell::Cell;

View file

@ -22,7 +22,7 @@ use super::io::process::ProcessConfig;
use super::io::net::ip::{IpAddr, SocketAddr}; use super::io::net::ip::{IpAddr, SocketAddr};
use path::Path; use path::Path;
use super::io::{SeekStyle}; use super::io::{SeekStyle};
use super::io::{FileMode, FileAccess, FileStat}; use super::io::{FileMode, FileAccess, FileStat, FilePermission};
pub trait EventLoop { pub trait EventLoop {
fn run(&mut self); fn run(&mut self);
@ -102,7 +102,10 @@ pub trait IoFactory {
-> Result<~RtioFileStream, IoError>; -> Result<~RtioFileStream, IoError>;
fn fs_unlink(&mut self, path: &CString) -> Result<(), IoError>; fn fs_unlink(&mut self, path: &CString) -> Result<(), IoError>;
fn fs_stat(&mut self, path: &CString) -> Result<FileStat, IoError>; fn fs_stat(&mut self, path: &CString) -> Result<FileStat, IoError>;
fn fs_mkdir(&mut self, path: &CString, mode: int) -> Result<(), IoError>; fn fs_mkdir(&mut self, path: &CString,
mode: FilePermission) -> Result<(), IoError>;
fn fs_chmod(&mut self, path: &CString,
mode: FilePermission) -> Result<(), IoError>;
fn fs_rmdir(&mut self, path: &CString) -> Result<(), IoError>; fn fs_rmdir(&mut self, path: &CString) -> Result<(), IoError>;
fn fs_rename(&mut self, path: &CString, to: &CString) -> Result<(), IoError>; fn fs_rename(&mut self, path: &CString, to: &CString) -> Result<(), IoError>;
fn fs_readdir(&mut self, path: &CString, flags: c_int) -> fn fs_readdir(&mut self, path: &CString, flags: c_int) ->

View file

@ -604,8 +604,8 @@ mod tests {
let parent_dir = os::getcwd(); let parent_dir = os::getcwd();
let child_dir = Path::new(output.trim()); let child_dir = Path::new(output.trim());
let parent_stat = parent_dir.stat().unwrap(); let parent_stat = parent_dir.stat();
let child_stat = child_dir.stat().unwrap(); let child_stat = child_dir.stat();
assert_eq!(parent_stat.device, child_stat.device); assert_eq!(parent_stat.device, child_stat.device);
assert_eq!(parent_stat.inode, child_stat.inode); assert_eq!(parent_stat.inode, child_stat.inode);
@ -621,8 +621,8 @@ mod tests {
let output = str::from_utf8(prog.finish_with_output().output); let output = str::from_utf8(prog.finish_with_output().output);
let child_dir = Path::new(output.trim()); let child_dir = Path::new(output.trim());
let parent_stat = parent_dir.stat().unwrap(); let parent_stat = parent_dir.stat();
let child_stat = child_dir.stat().unwrap(); let child_stat = child_dir.stat();
assert_eq!(parent_stat.device, child_stat.device); assert_eq!(parent_stat.device, child_stat.device);
assert_eq!(parent_stat.inode, child_stat.inode); assert_eq!(parent_stat.inode, child_stat.inode);

View file

@ -21,7 +21,7 @@ use print::pprust;
use std::rt::io; use std::rt::io;
use std::rt::io::Reader; use std::rt::io::Reader;
use std::rt::io::file::FileInfo; use std::rt::io::file;
use std::str; use std::str;
// These macros all relate to the file system; they either return // These macros all relate to the file system; they either return
@ -92,17 +92,13 @@ pub fn expand_include_str(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
-> base::MacResult { -> base::MacResult {
let file = get_single_str_from_tts(cx, sp, tts, "include_str!"); let file = get_single_str_from_tts(cx, sp, tts, "include_str!");
let file = res_rel_file(cx, sp, &Path::new(file)); let file = res_rel_file(cx, sp, &Path::new(file));
let mut error = None; let bytes = match io::result(|| file::open(&file).read_to_end()) {
let bytes = do io::io_error::cond.trap(|e| error = Some(e)).inside { Err(e) => {
file.open_reader(io::Open).read_to_end()
};
match error {
Some(e) => {
cx.span_fatal(sp, format!("couldn't read {}: {}", cx.span_fatal(sp, format!("couldn't read {}: {}",
file.display(), e.desc)); file.display(), e.desc));
} }
None => {} Ok(bytes) => bytes,
} };
match str::from_utf8_owned_opt(bytes) { match str::from_utf8_owned_opt(bytes) {
Some(s) => base::MRExpr(cx.expr_str(sp, s.to_managed())), Some(s) => base::MRExpr(cx.expr_str(sp, s.to_managed())),
None => { None => {
@ -118,17 +114,12 @@ pub fn expand_include_bin(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
let file = get_single_str_from_tts(cx, sp, tts, "include_bin!"); let file = get_single_str_from_tts(cx, sp, tts, "include_bin!");
let file = res_rel_file(cx, sp, &Path::new(file)); let file = res_rel_file(cx, sp, &Path::new(file));
match io::result(|| file::open(&file).read_to_end()) {
let mut error = None; Err(e) => {
let bytes = do io::io_error::cond.trap(|e| error = Some(e)).inside {
file.open_reader(io::Open).read_to_end()
};
match error {
Some(e) => {
cx.span_fatal(sp, format!("couldn't read {}: {}", cx.span_fatal(sp, format!("couldn't read {}: {}",
file.display(), e.desc)); file.display(), e.desc));
} }
None => { Ok(bytes) => {
let bytes = at_vec::to_managed_move(bytes); let bytes = at_vec::to_managed_move(bytes);
base::MRExpr(cx.expr_lit(sp, ast::lit_binary(bytes))) base::MRExpr(cx.expr_lit(sp, ast::lit_binary(bytes)))
} }

View file

@ -21,8 +21,7 @@ use parse::parser::Parser;
use std::path::Path; use std::path::Path;
use std::rt::io; use std::rt::io;
use std::rt::io::Reader; use std::rt::io::file;
use std::rt::io::file::FileInfo;
use std::str; use std::str;
pub mod lexer; pub mod lexer;
@ -269,16 +268,13 @@ pub fn file_to_filemap(sess: @mut ParseSess, path: &Path, spanopt: Option<Span>)
None => sess.span_diagnostic.handler().fatal(msg), None => sess.span_diagnostic.handler().fatal(msg),
} }
}; };
let mut error = None; let bytes = match io::result(|| file::open(path).read_to_end()) {
let bytes = do io::io_error::cond.trap(|e| error = Some(e)).inside { Ok(bytes) => bytes,
path.open_reader(io::Open).read_to_end() Err(e) => {
};
match error {
Some(e) => {
err(format!("couldn't read {}: {}", path.display(), e.desc)); err(format!("couldn't read {}: {}", path.display(), e.desc));
unreachable!()
} }
None => {} };
}
match str::from_utf8_owned_opt(bytes) { match str::from_utf8_owned_opt(bytes) {
Some(s) => { Some(s) => {
return string_to_filemap(sess, s.to_managed(), return string_to_filemap(sess, s.to_managed(),

View file

@ -597,6 +597,10 @@ rust_uv_fs_rename(uv_loop_t *loop, uv_fs_t* req, const char *path,
const char *to, uv_fs_cb cb) { const char *to, uv_fs_cb cb) {
return uv_fs_rename(loop, req, path, to, cb); return uv_fs_rename(loop, req, path, to, cb);
} }
extern "C" int
rust_uv_fs_chmod(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode, uv_fs_cb cb) {
return uv_fs_chmod(loop, req, path, mode, cb);
}
extern "C" int extern "C" int
rust_uv_spawn(uv_loop_t *loop, uv_process_t *p, uv_process_options_t options) { rust_uv_spawn(uv_loop_t *loop, uv_process_t *p, uv_process_options_t options) {

View file

@ -21,6 +21,7 @@ use std::rand;
use std::str; use std::str;
use std::util; use std::util;
use std::vec; use std::vec;
use std::rt::io::file;
macro_rules! bench ( macro_rules! bench (
($argv:expr, $id:ident) => (maybe_run_test($argv, stringify!($id).to_owned(), $id)) ($argv:expr, $id:ident) => (maybe_run_test($argv, stringify!($id).to_owned(), $id))
@ -69,15 +70,13 @@ fn shift_push() {
} }
fn read_line() { fn read_line() {
use std::rt::io::{Reader, Open};
use std::rt::io::file::FileInfo;
use std::rt::io::buffered::BufferedReader; use std::rt::io::buffered::BufferedReader;
let mut path = Path::new(env!("CFG_SRC_DIR")); let mut path = Path::new(env!("CFG_SRC_DIR"));
path.push("src/test/bench/shootout-k-nucleotide.data"); path.push("src/test/bench/shootout-k-nucleotide.data");
for _ in range(0, 3) { for _ in range(0, 3) {
let mut reader = BufferedReader::new(path.open_reader(Open).unwrap()); let mut reader = BufferedReader::new(file::open(&path).unwrap());
while !reader.eof() { while !reader.eof() {
reader.read_line(); reader.read_line();
} }

View file

@ -19,6 +19,7 @@ extern mod extra;
use std::int; use std::int;
use std::rt::io; use std::rt::io;
use std::rt::io::file;
use std::os; use std::os;
use std::rand::Rng; use std::rand::Rng;
use std::rand; use std::rand;
@ -111,7 +112,6 @@ fn acid(ch: char, prob: u32) -> AminoAcids {
} }
fn main() { fn main() {
use std::rt::io::file::FileInfo;
let args = os::args(); let args = os::args();
let args = if os::getenv("RUST_BENCH").is_some() { let args = if os::getenv("RUST_BENCH").is_some() {
// alioth tests k-nucleotide with this data at 25,000,000 // alioth tests k-nucleotide with this data at 25,000,000
@ -123,7 +123,7 @@ fn main() {
}; };
let writer = if os::getenv("RUST_BENCH").is_some() { let writer = if os::getenv("RUST_BENCH").is_some() {
let file = Path::new("./shootout-fasta.data").open_writer(io::CreateOrTruncate); let file = file::create(&Path::new("./shootout-fasta.data"));
@mut file as @mut io::Writer @mut file as @mut io::Writer
} else { } else {
@mut io::stdout() as @mut io::Writer @mut io::stdout() as @mut io::Writer

View file

@ -9,6 +9,7 @@
// except according to those terms. // except according to those terms.
// xfail-pretty // xfail-pretty
// xfail-test
extern mod extra; extern mod extra;
extern mod syntax; extern mod syntax;

View file

@ -8,6 +8,10 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// xfail-test
#[feature(managed_boxes)];
extern mod syntax; extern mod syntax;
use syntax::ext::base::ExtCtxt; use syntax::ext::base::ExtCtxt;
@ -16,11 +20,11 @@ fn syntax_extension(cx: @ExtCtxt) {
let e_toks : ~[syntax::ast::token_tree] = quote_tokens!(cx, 1 + 2); let e_toks : ~[syntax::ast::token_tree] = quote_tokens!(cx, 1 + 2);
let p_toks : ~[syntax::ast::token_tree] = quote_tokens!(cx, (x, 1 .. 4, *)); let p_toks : ~[syntax::ast::token_tree] = quote_tokens!(cx, (x, 1 .. 4, *));
let a: @syntax::ast::expr = quote_expr!(cx, 1 + 2); let a: @syntax::ast::Expr = quote_expr!(cx, 1 + 2);
let _b: Option<@syntax::ast::item> = quote_item!(cx, static foo : int = $e_toks; ); let _b: Option<@syntax::ast::item> = quote_item!(cx, static foo : int = $e_toks; );
let _c: @syntax::ast::pat = quote_pat!(cx, (x, 1 .. 4, *) ); let _c: @syntax::ast::Pat = quote_pat!(cx, (x, 1 .. 4, *) );
let _d: @syntax::ast::stmt = quote_stmt!(cx, let x = $a; ); let _d: @syntax::ast::Stmt = quote_stmt!(cx, let x = $a; );
let _e: @syntax::ast::expr = quote_expr!(cx, match foo { $p_toks => 10 } ); let _e: @syntax::ast::Expr = quote_expr!(cx, match foo { $p_toks => 10 } );
} }
fn main() { fn main() {

View file

@ -17,14 +17,13 @@ use extra::tempfile::TempDir;
use std::unstable::finally::Finally; use std::unstable::finally::Finally;
use std::{os, unstable}; use std::{os, unstable};
use std::rt::io; use std::rt::io;
use std::rt::io::file::FileInfo;
pub fn main() { pub fn main() {
fn mk_file(path: &str, directory: bool) { fn mk_file(path: &str, directory: bool) {
if directory { if directory {
os::make_dir(&Path::new(path), 0xFFFF); io::file::mkdir(&Path::new(path), io::UserRWX);
} else { } else {
Path::new(path).open_writer(io::Create); io::file::create(&Path::new(path));
} }
} }

View file

@ -17,6 +17,8 @@ extern mod extra;
use extra::tempfile::TempDir; use extra::tempfile::TempDir;
use std::os; use std::os;
use std::libc; use std::libc;
use std::rt::io;
use std::rt::io::file;
fn rename_directory() { fn rename_directory() {
#[fixed_stack_segment]; #[fixed_stack_segment];
@ -26,7 +28,7 @@ fn rename_directory() {
let tmpdir = TempDir::new("rename_directory").expect("rename_directory failed"); let tmpdir = TempDir::new("rename_directory").expect("rename_directory failed");
let tmpdir = tmpdir.path(); let tmpdir = tmpdir.path();
let old_path = tmpdir.join_many(["foo", "bar", "baz"]); let old_path = tmpdir.join_many(["foo", "bar", "baz"]);
assert!(os::mkdir_recursive(&old_path, U_RWX)); file::mkdir_recursive(&old_path, io::UserRWX);
let test_file = &old_path.join("temp.txt"); let test_file = &old_path.join("temp.txt");
/* Write the temp input file */ /* Write the temp input file */
@ -47,10 +49,10 @@ fn rename_directory() {
assert_eq!(libc::fclose(ostream), (0u as libc::c_int)); assert_eq!(libc::fclose(ostream), (0u as libc::c_int));
let new_path = tmpdir.join_many(["quux", "blat"]); let new_path = tmpdir.join_many(["quux", "blat"]);
assert!(os::mkdir_recursive(&new_path, U_RWX)); file::mkdir_recursive(&new_path, io::UserRWX);
assert!(os::rename_file(&old_path, &new_path.join("newdir"))); file::rename(&old_path, &new_path.join("newdir"));
assert!(os::path_is_dir(&new_path.join("newdir"))); assert!(new_path.join("newdir").is_dir());
assert!(os::path_exists(&new_path.join_many(["newdir", "temp.txt"]))); assert!(new_path.join_many(["newdir", "temp.txt"]).exists());
} }
} }

View file

@ -13,17 +13,14 @@
extern mod extra; extern mod extra;
use extra::tempfile; use extra::tempfile;
use std::rt::io; use std::rt::io::file;
use std::rt::io::Writer;
use std::rt::io::file::FileInfo;
use std::os;
pub fn main() { pub fn main() {
let dir = tempfile::TempDir::new_in(&Path::new("."), "").unwrap(); let dir = tempfile::TempDir::new_in(&Path::new("."), "").unwrap();
let path = dir.path().join("file"); let path = dir.path().join("file");
{ {
match path.open_writer(io::CreateOrTruncate) { match file::create(&path) {
None => unreachable!(), None => unreachable!(),
Some(f) => { Some(f) => {
let mut f = f; let mut f = f;
@ -35,5 +32,5 @@ pub fn main() {
} }
assert!(path.exists()); assert!(path.exists());
assert_eq!(path.get_size(), Some(1000)); assert_eq!(path.stat().size, 1000);
} }

View file

@ -22,9 +22,10 @@ extern mod extra;
use extra::tempfile::TempDir; use extra::tempfile::TempDir;
use std::os; use std::os;
use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
use std::task; use std::task;
use std::cell::Cell; use std::cell::Cell;
use std::rt::io;
use std::rt::io::file;
fn test_tempdir() { fn test_tempdir() {
let path = { let path = {
@ -33,7 +34,7 @@ fn test_tempdir() {
assert!(p.as_vec().ends_with(bytes!("foobar"))); assert!(p.as_vec().ends_with(bytes!("foobar")));
p.clone() p.clone()
}; };
assert!(!os::path_exists(&path)); assert!(!path.exists());
} }
fn test_rm_tempdir() { fn test_rm_tempdir() {
@ -45,7 +46,7 @@ fn test_rm_tempdir() {
}; };
task::try(f); task::try(f);
let path = rd.recv(); let path = rd.recv();
assert!(!os::path_exists(&path)); assert!(!path.exists());
let tmp = TempDir::new("test_rm_tempdir").unwrap(); let tmp = TempDir::new("test_rm_tempdir").unwrap();
let path = tmp.path().clone(); let path = tmp.path().clone();
@ -55,7 +56,7 @@ fn test_rm_tempdir() {
fail!("fail to unwind past `tmp`"); fail!("fail to unwind past `tmp`");
}; };
task::try(f); task::try(f);
assert!(!os::path_exists(&path)); assert!(!path.exists());
let path; let path;
{ {
@ -64,18 +65,18 @@ fn test_rm_tempdir() {
}; };
let tmp = task::try(f).expect("test_rm_tmdir"); let tmp = task::try(f).expect("test_rm_tmdir");
path = tmp.path().clone(); path = tmp.path().clone();
assert!(os::path_exists(&path)); assert!(path.exists());
} }
assert!(!os::path_exists(&path)); assert!(!path.exists());
let path; let path;
{ {
let tmp = TempDir::new("test_rm_tempdir").unwrap(); let tmp = TempDir::new("test_rm_tempdir").unwrap();
path = tmp.unwrap(); path = tmp.unwrap();
} }
assert!(os::path_exists(&path)); assert!(path.exists());
os::remove_dir_recursive(&path); file::rmdir_recursive(&path);
assert!(!os::path_exists(&path)); assert!(!path.exists());
} }
// Ideally these would be in std::os but then core would need // Ideally these would be in std::os but then core would need
@ -84,39 +85,39 @@ fn recursive_mkdir_rel() {
let path = Path::new("frob"); let path = Path::new("frob");
let cwd = os::getcwd(); let cwd = os::getcwd();
debug!("recursive_mkdir_rel: Making: {} in cwd {} [{:?}]", path.display(), debug!("recursive_mkdir_rel: Making: {} in cwd {} [{:?}]", path.display(),
cwd.display(), os::path_exists(&path)); cwd.display(), path.exists());
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32)); file::mkdir_recursive(&path, io::UserRWX);
assert!(os::path_is_dir(&path)); assert!(path.is_dir());
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32)); file::mkdir_recursive(&path, io::UserRWX);
assert!(os::path_is_dir(&path)); assert!(path.is_dir());
} }
fn recursive_mkdir_dot() { fn recursive_mkdir_dot() {
let dot = Path::new("."); let dot = Path::new(".");
assert!(os::mkdir_recursive(&dot, (S_IRUSR | S_IWUSR | S_IXUSR) as i32)); file::mkdir_recursive(&dot, io::UserRWX);
let dotdot = Path::new(".."); let dotdot = Path::new("..");
assert!(os::mkdir_recursive(&dotdot, (S_IRUSR | S_IWUSR | S_IXUSR) as i32)); file::mkdir_recursive(&dotdot, io::UserRWX);
} }
fn recursive_mkdir_rel_2() { fn recursive_mkdir_rel_2() {
let path = Path::new("./frob/baz"); let path = Path::new("./frob/baz");
let cwd = os::getcwd(); let cwd = os::getcwd();
debug!("recursive_mkdir_rel_2: Making: {} in cwd {} [{:?}]", path.display(), debug!("recursive_mkdir_rel_2: Making: {} in cwd {} [{:?}]", path.display(),
cwd.display(), os::path_exists(&path)); cwd.display(), path.exists());
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32)); file::mkdir_recursive(&path, io::UserRWX);
assert!(os::path_is_dir(&path)); assert!(path.is_dir());
assert!(os::path_is_dir(&path.dir_path())); assert!(path.dir_path().is_dir());
let path2 = Path::new("quux/blat"); let path2 = Path::new("quux/blat");
debug!("recursive_mkdir_rel_2: Making: {} in cwd {}", path2.display(), debug!("recursive_mkdir_rel_2: Making: {} in cwd {}", path2.display(),
cwd.display()); cwd.display());
assert!(os::mkdir_recursive(&path2, (S_IRUSR | S_IWUSR | S_IXUSR) as i32)); file::mkdir_recursive(&path2, io::UserRWX);
assert!(os::path_is_dir(&path2)); assert!(path2.is_dir());
assert!(os::path_is_dir(&path2.dir_path())); assert!(path2.dir_path().is_dir());
} }
// Ideally this would be in core, but needs TempFile // Ideally this would be in core, but needs TempFile
pub fn test_rmdir_recursive_ok() { pub fn test_rmdir_recursive_ok() {
let rwx = (S_IRUSR | S_IWUSR | S_IXUSR) as i32; let rwx = io::UserRWX;
let tmpdir = TempDir::new("test").expect("test_rmdir_recursive_ok: \ let tmpdir = TempDir::new("test").expect("test_rmdir_recursive_ok: \
couldn't create temp dir"); couldn't create temp dir");
@ -124,14 +125,14 @@ pub fn test_rmdir_recursive_ok() {
let root = tmpdir.join("foo"); let root = tmpdir.join("foo");
debug!("making {}", root.display()); debug!("making {}", root.display());
assert!(os::make_dir(&root, rwx)); file::mkdir(&root, rwx);
assert!(os::make_dir(&root.join("foo"), rwx)); file::mkdir(&root.join("foo"), rwx);
assert!(os::make_dir(&root.join("foo").join("bar"), rwx)); file::mkdir(&root.join("foo").join("bar"), rwx);
assert!(os::make_dir(&root.join("foo").join("bar").join("blat"), rwx)); file::mkdir(&root.join("foo").join("bar").join("blat"), rwx);
assert!(os::remove_dir_recursive(&root)); file::rmdir_recursive(&root);
assert!(!os::path_exists(&root)); assert!(!root.exists());
assert!(!os::path_exists(&root.join("bar"))); assert!(!root.join("bar").exists());
assert!(!os::path_exists(&root.join("bar").join("blat"))); assert!(!root.join("bar").join("blat").exists());
} }
fn in_tmpdir(f: &fn()) { fn in_tmpdir(f: &fn()) {