rtio: Remove usage of Path
The rtio interface is a thin low-level interface over the I/O subsystems, and the `Path` type is a little too high-level for this interface.
This commit is contained in:
parent
b830b4b86b
commit
a3f9aa9ef8
@ -361,17 +361,17 @@ pub fn mkdir(p: &CString, mode: io::FilePermission) -> IoResult<()> {
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn readdir(p: &CString) -> IoResult<Vec<Path>> {
|
||||
pub fn readdir(p: &CString) -> IoResult<Vec<CString>> {
|
||||
use libc::{dirent_t};
|
||||
use libc::{opendir, readdir_r, closedir};
|
||||
|
||||
fn prune(root: &CString, dirs: Vec<Path>) -> Vec<Path> {
|
||||
fn prune(root: &CString, dirs: Vec<Path>) -> Vec<CString> {
|
||||
let root = unsafe { CString::new(root.with_ref(|p| p), false) };
|
||||
let root = Path::new(root);
|
||||
|
||||
dirs.move_iter().filter(|path| {
|
||||
path.as_vec() != bytes!(".") && path.as_vec() != bytes!("..")
|
||||
}).map(|path| root.join(path)).collect()
|
||||
}).map(|path| root.join(path).to_c_str()).collect()
|
||||
}
|
||||
|
||||
extern {
|
||||
@ -431,7 +431,7 @@ pub fn chown(p: &CString, uid: int, gid: int) -> IoResult<()> {
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn readlink(p: &CString) -> IoResult<Path> {
|
||||
pub fn readlink(p: &CString) -> IoResult<CString> {
|
||||
let p = p.with_ref(|p| p);
|
||||
let mut len = unsafe { libc::pathconf(p, libc::_PC_NAME_MAX) };
|
||||
if len == -1 {
|
||||
@ -446,7 +446,7 @@ pub fn readlink(p: &CString) -> IoResult<Path> {
|
||||
n => {
|
||||
assert!(n > 0);
|
||||
unsafe { buf.set_len(n as uint); }
|
||||
Ok(Path::new(buf))
|
||||
Ok(buf.as_slice().to_c_str())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -347,16 +347,16 @@ pub fn mkdir(p: &CString, _mode: io::FilePermission) -> IoResult<()> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn readdir(p: &CString) -> IoResult<Vec<Path>> {
|
||||
pub fn readdir(p: &CString) -> IoResult<Vec<CString>> {
|
||||
use std::rt::libc_heap::malloc_raw;
|
||||
|
||||
fn prune(root: &CString, dirs: Vec<Path>) -> Vec<Path> {
|
||||
fn prune(root: &CString, dirs: Vec<Path>) -> Vec<CString> {
|
||||
let root = unsafe { CString::new(root.with_ref(|p| p), false) };
|
||||
let root = Path::new(root);
|
||||
|
||||
dirs.move_iter().filter(|path| {
|
||||
path.as_vec() != bytes!(".") && path.as_vec() != bytes!("..")
|
||||
}).map(|path| root.join(path)).collect()
|
||||
}).map(|path| root.join(path).to_c_str()).collect()
|
||||
}
|
||||
|
||||
extern {
|
||||
|
@ -232,7 +232,7 @@ impl rtio::IoFactory for IoFactory {
|
||||
fn fs_rename(&mut self, path: &CString, to: &CString) -> IoResult<()> {
|
||||
file::rename(path, to)
|
||||
}
|
||||
fn fs_readdir(&mut self, path: &CString, _flags: c_int) -> IoResult<Vec<Path>> {
|
||||
fn fs_readdir(&mut self, path: &CString, _flags: c_int) -> IoResult<Vec<CString>> {
|
||||
file::readdir(path)
|
||||
}
|
||||
fn fs_lstat(&mut self, path: &CString) -> IoResult<io::FileStat> {
|
||||
@ -241,7 +241,7 @@ impl rtio::IoFactory for IoFactory {
|
||||
fn fs_chown(&mut self, path: &CString, uid: int, gid: int) -> IoResult<()> {
|
||||
file::chown(path, uid, gid)
|
||||
}
|
||||
fn fs_readlink(&mut self, path: &CString) -> IoResult<Path> {
|
||||
fn fs_readlink(&mut self, path: &CString) -> IoResult<CString> {
|
||||
file::readlink(path)
|
||||
}
|
||||
fn fs_symlink(&mut self, src: &CString, dst: &CString) -> IoResult<()> {
|
||||
|
@ -157,7 +157,7 @@ impl FsRequest {
|
||||
}
|
||||
|
||||
pub fn readdir(loop_: &Loop, path: &CString, flags: c_int)
|
||||
-> Result<Vec<Path>, UvError>
|
||||
-> Result<Vec<CString>, UvError>
|
||||
{
|
||||
execute(|req, cb| unsafe {
|
||||
uvll::uv_fs_readdir(loop_.handle,
|
||||
@ -170,20 +170,22 @@ impl FsRequest {
|
||||
Some(req.get_result() as uint),
|
||||
|rel| {
|
||||
let p = rel.as_bytes();
|
||||
paths.push(parent.join(p.slice_to(rel.len())));
|
||||
paths.push(parent.join(p.slice_to(rel.len())).to_c_str());
|
||||
});
|
||||
paths
|
||||
})
|
||||
}
|
||||
|
||||
pub fn readlink(loop_: &Loop, path: &CString) -> Result<Path, UvError> {
|
||||
pub fn readlink(loop_: &Loop, path: &CString) -> Result<CString, UvError> {
|
||||
execute(|req, cb| unsafe {
|
||||
uvll::uv_fs_readlink(loop_.handle, req,
|
||||
path.with_ref(|p| p), cb)
|
||||
}).map(|req| {
|
||||
Path::new(unsafe {
|
||||
CString::new(req.get_ptr() as *libc::c_char, false)
|
||||
})
|
||||
// Be sure to clone the cstring so we get an independently owned
|
||||
// allocation to work with and return.
|
||||
unsafe {
|
||||
CString::new(req.get_ptr() as *libc::c_char, false).clone()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,6 @@ use libc::c_int;
|
||||
use libc::{O_CREAT, O_APPEND, O_TRUNC, O_RDWR, O_RDONLY, O_WRONLY, S_IRUSR,
|
||||
S_IWUSR};
|
||||
use libc;
|
||||
use std::path::Path;
|
||||
use std::rt::rtio;
|
||||
use std::rt::rtio::{ProcessConfig, IoFactory, EventLoop};
|
||||
use ai = std::io::net::addrinfo;
|
||||
@ -241,7 +240,7 @@ impl IoFactory for UvIoFactory {
|
||||
r.map_err(uv_error_to_io_error)
|
||||
}
|
||||
fn fs_readdir(&mut self, path: &CString, flags: c_int)
|
||||
-> Result<Vec<Path>, IoError>
|
||||
-> Result<Vec<CString>, IoError>
|
||||
{
|
||||
let r = FsRequest::readdir(&self.loop_, path, flags);
|
||||
r.map_err(uv_error_to_io_error)
|
||||
@ -258,7 +257,7 @@ impl IoFactory for UvIoFactory {
|
||||
let r = FsRequest::chown(&self.loop_, path, uid, gid);
|
||||
r.map_err(uv_error_to_io_error)
|
||||
}
|
||||
fn fs_readlink(&mut self, path: &CString) -> Result<Path, IoError> {
|
||||
fn fs_readlink(&mut self, path: &CString) -> Result<CString, IoError> {
|
||||
let r = FsRequest::readlink(&self.loop_, path);
|
||||
r.map_err(uv_error_to_io_error)
|
||||
}
|
||||
|
@ -410,7 +410,9 @@ pub fn symlink(src: &Path, dst: &Path) -> IoResult<()> {
|
||||
/// This function will return an error on failure. Failure conditions include
|
||||
/// reading a file that does not exist or reading a file which is not a symlink.
|
||||
pub fn readlink(path: &Path) -> IoResult<Path> {
|
||||
LocalIo::maybe_raise(|io| io.fs_readlink(&path.to_c_str()))
|
||||
LocalIo::maybe_raise(|io| {
|
||||
Ok(Path::new(try!(io.fs_readlink(&path.to_c_str()))))
|
||||
})
|
||||
}
|
||||
|
||||
/// Create a new, empty directory at the provided path
|
||||
@ -487,7 +489,9 @@ pub fn rmdir(path: &Path) -> IoResult<()> {
|
||||
/// file
|
||||
pub fn readdir(path: &Path) -> IoResult<Vec<Path>> {
|
||||
LocalIo::maybe_raise(|io| {
|
||||
io.fs_readdir(&path.to_c_str(), 0)
|
||||
Ok(try!(io.fs_readdir(&path.to_c_str(), 0)).move_iter().map(|a| {
|
||||
Path::new(a)
|
||||
}).collect())
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,6 @@ use mem;
|
||||
use ops::Drop;
|
||||
use option::{Option, Some, None};
|
||||
use owned::Box;
|
||||
use path::Path;
|
||||
use result::Err;
|
||||
use rt::local::Local;
|
||||
use rt::task::Task;
|
||||
@ -223,11 +222,11 @@ pub trait IoFactory {
|
||||
fn fs_rmdir(&mut self, path: &CString) -> IoResult<()>;
|
||||
fn fs_rename(&mut self, path: &CString, to: &CString) -> IoResult<()>;
|
||||
fn fs_readdir(&mut self, path: &CString, flags: c_int) ->
|
||||
IoResult<Vec<Path>>;
|
||||
IoResult<Vec<CString>>;
|
||||
fn fs_lstat(&mut self, path: &CString) -> IoResult<FileStat>;
|
||||
fn fs_chown(&mut self, path: &CString, uid: int, gid: int) ->
|
||||
IoResult<()>;
|
||||
fn fs_readlink(&mut self, path: &CString) -> IoResult<Path>;
|
||||
fn fs_readlink(&mut self, path: &CString) -> IoResult<CString>;
|
||||
fn fs_symlink(&mut self, src: &CString, dst: &CString) -> IoResult<()>;
|
||||
fn fs_link(&mut self, src: &CString, dst: &CString) -> IoResult<()>;
|
||||
fn fs_utime(&mut self, src: &CString, atime: u64, mtime: u64) ->
|
||||
|
Loading…
Reference in New Issue
Block a user