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:
parent
7bf58c2baa
commit
9c1851019f
57 changed files with 1364 additions and 1493 deletions
|
@ -24,9 +24,6 @@ use vec;
|
|||
use vec::{CopyableVector, RSplitIterator, SplitIterator, Vector, VectorVector};
|
||||
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]
|
||||
pub type ComponentIter<'self> = SplitIterator<'self, 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_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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue