mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-02 18:12:51 +00:00
std,native,green,rustuv: make readdir return Vec
.
Replacing `~[]`. This also makes the `walk_dir` iterator use a `Vec` internally.
This commit is contained in:
parent
a65411e4f7
commit
301594917f
@ -340,11 +340,11 @@ pub fn mkdir(p: &CString, mode: io::FilePermission) -> IoResult<()> {
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn readdir(p: &CString) -> IoResult<~[Path]> {
|
||||
pub fn readdir(p: &CString) -> IoResult<Vec<Path>> {
|
||||
use libc::{dirent_t};
|
||||
use libc::{opendir, readdir_r, closedir};
|
||||
|
||||
fn prune(root: &CString, dirs: ~[Path]) -> ~[Path] {
|
||||
fn prune(root: &CString, dirs: Vec<Path>) -> Vec<Path> {
|
||||
let root = unsafe { CString::new(root.with_ref(|p| p), false) };
|
||||
let root = Path::new(root);
|
||||
|
||||
@ -365,7 +365,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> {
|
||||
let dir_ptr = p.with_ref(|buf| unsafe { opendir(buf) });
|
||||
|
||||
if dir_ptr as uint != 0 {
|
||||
let mut paths = ~[];
|
||||
let mut paths = vec!();
|
||||
let mut entry_ptr = 0 as *mut dirent_t;
|
||||
while unsafe { readdir_r(dir_ptr, ptr, &mut entry_ptr) == 0 } {
|
||||
if entry_ptr.is_null() { break }
|
||||
@ -571,4 +571,3 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -323,10 +323,10 @@ pub fn mkdir(p: &CString, _mode: io::FilePermission) -> IoResult<()> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn readdir(p: &CString) -> IoResult<~[Path]> {
|
||||
pub fn readdir(p: &CString) -> IoResult<Vec<Path>> {
|
||||
use rt::global_heap::malloc_raw;
|
||||
|
||||
fn prune(root: &CString, dirs: ~[Path]) -> ~[Path] {
|
||||
fn prune(root: &CString, dirs: Vec<Path>) -> Vec<Path> {
|
||||
let root = unsafe { CString::new(root.with_ref(|p| p), false) };
|
||||
let root = Path::new(root);
|
||||
|
||||
@ -346,7 +346,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> {
|
||||
let wfd_ptr = malloc_raw(rust_list_dir_wfd_size() as uint);
|
||||
let find_handle = libc::FindFirstFileW(path_ptr, wfd_ptr as libc::HANDLE);
|
||||
if find_handle as libc::c_int != libc::INVALID_HANDLE_VALUE {
|
||||
let mut paths = ~[];
|
||||
let mut paths = vec!();
|
||||
let mut more_files = 1 as libc::c_int;
|
||||
while more_files != 0 {
|
||||
let fp_buf = rust_list_dir_wfd_fp_buf(wfd_ptr as *c_void);
|
||||
|
@ -217,7 +217,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<~[Path]> {
|
||||
fn fs_readdir(&mut self, path: &CString, _flags: c_int) -> IoResult<Vec<Path>> {
|
||||
file::readdir(path)
|
||||
}
|
||||
fn fs_lstat(&mut self, path: &CString) -> IoResult<io::FileStat> {
|
||||
|
@ -152,13 +152,13 @@ impl FsRequest {
|
||||
}
|
||||
|
||||
pub fn readdir(loop_: &Loop, path: &CString, flags: c_int)
|
||||
-> Result<~[Path], UvError>
|
||||
-> Result<Vec<Path>, UvError>
|
||||
{
|
||||
execute(|req, cb| unsafe {
|
||||
uvll::uv_fs_readdir(loop_.handle,
|
||||
req, path.with_ref(|p| p), flags, cb)
|
||||
}).map(|req| unsafe {
|
||||
let mut paths = ~[];
|
||||
let mut paths = vec!();
|
||||
let path = CString::new(path.with_ref(|p| p), false);
|
||||
let parent = Path::new(path);
|
||||
let _ = c_str::from_c_multistring(req.get_ptr() as *libc::c_char,
|
||||
|
@ -234,7 +234,7 @@ impl IoFactory for UvIoFactory {
|
||||
r.map_err(uv_error_to_io_error)
|
||||
}
|
||||
fn fs_readdir(&mut self, path: &CString, flags: c_int)
|
||||
-> Result<~[Path], IoError>
|
||||
-> Result<Vec<Path>, IoError>
|
||||
{
|
||||
let r = FsRequest::readdir(&self.loop_, path, flags);
|
||||
r.map_err(uv_error_to_io_error)
|
||||
|
@ -483,7 +483,7 @@ pub fn rmdir(path: &Path) -> IoResult<()> {
|
||||
/// Will return an error if the provided `from` doesn't exist, the process lacks
|
||||
/// permissions to view the contents or if the `path` points at a non-directory
|
||||
/// file
|
||||
pub fn readdir(path: &Path) -> IoResult<~[Path]> {
|
||||
pub fn readdir(path: &Path) -> IoResult<Vec<Path>> {
|
||||
LocalIo::maybe_raise(|io| {
|
||||
io.fs_readdir(&path.to_c_str(), 0)
|
||||
})
|
||||
@ -498,7 +498,7 @@ pub fn walk_dir(path: &Path) -> IoResult<Directories> {
|
||||
|
||||
/// An iterator which walks over a directory
|
||||
pub struct Directories {
|
||||
stack: ~[Path],
|
||||
stack: Vec<Path>,
|
||||
}
|
||||
|
||||
impl Iterator<Path> for Directories {
|
||||
|
@ -20,6 +20,7 @@ use path::Path;
|
||||
use result::Err;
|
||||
use rt::local::Local;
|
||||
use rt::task::Task;
|
||||
use vec::Vec;
|
||||
|
||||
use ai = io::net::addrinfo;
|
||||
use io;
|
||||
@ -168,7 +169,7 @@ 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<~[Path]>;
|
||||
IoResult<Vec<Path>>;
|
||||
fn fs_lstat(&mut self, path: &CString) -> IoResult<FileStat>;
|
||||
fn fs_chown(&mut self, path: &CString, uid: int, gid: int) ->
|
||||
IoResult<()>;
|
||||
|
Loading…
Reference in New Issue
Block a user