}))
}
-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 {
}))
}
-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 {
n => {
assert!(n > 0);
unsafe { buf.set_len(n as uint); }
- Ok(Path::new(buf))
+ Ok(buf.as_slice().to_c_str())
}
}
}
})
}
-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 {
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> {
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<()> {
}
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,
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()
+ }
})
}
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;
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)
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)
}
/// 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
/// 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())
})
}
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;
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) ->