Skip to content

Commit a3f9aa9

Browse files
committed
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.
1 parent b830b4b commit a3f9aa9

File tree

7 files changed

+28
-24
lines changed

7 files changed

+28
-24
lines changed

src/libnative/io/file_unix.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,17 +361,17 @@ pub fn mkdir(p: &CString, mode: io::FilePermission) -> IoResult<()> {
361361
}))
362362
}
363363

364-
pub fn readdir(p: &CString) -> IoResult<Vec<Path>> {
364+
pub fn readdir(p: &CString) -> IoResult<Vec<CString>> {
365365
use libc::{dirent_t};
366366
use libc::{opendir, readdir_r, closedir};
367367

368-
fn prune(root: &CString, dirs: Vec<Path>) -> Vec<Path> {
368+
fn prune(root: &CString, dirs: Vec<Path>) -> Vec<CString> {
369369
let root = unsafe { CString::new(root.with_ref(|p| p), false) };
370370
let root = Path::new(root);
371371

372372
dirs.move_iter().filter(|path| {
373373
path.as_vec() != bytes!(".") && path.as_vec() != bytes!("..")
374-
}).map(|path| root.join(path)).collect()
374+
}).map(|path| root.join(path).to_c_str()).collect()
375375
}
376376

377377
extern {
@@ -431,7 +431,7 @@ pub fn chown(p: &CString, uid: int, gid: int) -> IoResult<()> {
431431
}))
432432
}
433433

434-
pub fn readlink(p: &CString) -> IoResult<Path> {
434+
pub fn readlink(p: &CString) -> IoResult<CString> {
435435
let p = p.with_ref(|p| p);
436436
let mut len = unsafe { libc::pathconf(p, libc::_PC_NAME_MAX) };
437437
if len == -1 {
@@ -446,7 +446,7 @@ pub fn readlink(p: &CString) -> IoResult<Path> {
446446
n => {
447447
assert!(n > 0);
448448
unsafe { buf.set_len(n as uint); }
449-
Ok(Path::new(buf))
449+
Ok(buf.as_slice().to_c_str())
450450
}
451451
}
452452
}

src/libnative/io/file_win32.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,16 +347,16 @@ pub fn mkdir(p: &CString, _mode: io::FilePermission) -> IoResult<()> {
347347
})
348348
}
349349

350-
pub fn readdir(p: &CString) -> IoResult<Vec<Path>> {
350+
pub fn readdir(p: &CString) -> IoResult<Vec<CString>> {
351351
use std::rt::libc_heap::malloc_raw;
352352

353-
fn prune(root: &CString, dirs: Vec<Path>) -> Vec<Path> {
353+
fn prune(root: &CString, dirs: Vec<Path>) -> Vec<CString> {
354354
let root = unsafe { CString::new(root.with_ref(|p| p), false) };
355355
let root = Path::new(root);
356356

357357
dirs.move_iter().filter(|path| {
358358
path.as_vec() != bytes!(".") && path.as_vec() != bytes!("..")
359-
}).map(|path| root.join(path)).collect()
359+
}).map(|path| root.join(path).to_c_str()).collect()
360360
}
361361

362362
extern {

src/libnative/io/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl rtio::IoFactory for IoFactory {
232232
fn fs_rename(&mut self, path: &CString, to: &CString) -> IoResult<()> {
233233
file::rename(path, to)
234234
}
235-
fn fs_readdir(&mut self, path: &CString, _flags: c_int) -> IoResult<Vec<Path>> {
235+
fn fs_readdir(&mut self, path: &CString, _flags: c_int) -> IoResult<Vec<CString>> {
236236
file::readdir(path)
237237
}
238238
fn fs_lstat(&mut self, path: &CString) -> IoResult<io::FileStat> {
@@ -241,7 +241,7 @@ impl rtio::IoFactory for IoFactory {
241241
fn fs_chown(&mut self, path: &CString, uid: int, gid: int) -> IoResult<()> {
242242
file::chown(path, uid, gid)
243243
}
244-
fn fs_readlink(&mut self, path: &CString) -> IoResult<Path> {
244+
fn fs_readlink(&mut self, path: &CString) -> IoResult<CString> {
245245
file::readlink(path)
246246
}
247247
fn fs_symlink(&mut self, src: &CString, dst: &CString) -> IoResult<()> {

src/librustuv/file.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl FsRequest {
157157
}
158158

159159
pub fn readdir(loop_: &Loop, path: &CString, flags: c_int)
160-
-> Result<Vec<Path>, UvError>
160+
-> Result<Vec<CString>, UvError>
161161
{
162162
execute(|req, cb| unsafe {
163163
uvll::uv_fs_readdir(loop_.handle,
@@ -170,20 +170,22 @@ impl FsRequest {
170170
Some(req.get_result() as uint),
171171
|rel| {
172172
let p = rel.as_bytes();
173-
paths.push(parent.join(p.slice_to(rel.len())));
173+
paths.push(parent.join(p.slice_to(rel.len())).to_c_str());
174174
});
175175
paths
176176
})
177177
}
178178

179-
pub fn readlink(loop_: &Loop, path: &CString) -> Result<Path, UvError> {
179+
pub fn readlink(loop_: &Loop, path: &CString) -> Result<CString, UvError> {
180180
execute(|req, cb| unsafe {
181181
uvll::uv_fs_readlink(loop_.handle, req,
182182
path.with_ref(|p| p), cb)
183183
}).map(|req| {
184-
Path::new(unsafe {
185-
CString::new(req.get_ptr() as *libc::c_char, false)
186-
})
184+
// Be sure to clone the cstring so we get an independently owned
185+
// allocation to work with and return.
186+
unsafe {
187+
CString::new(req.get_ptr() as *libc::c_char, false).clone()
188+
}
187189
})
188190
}
189191

src/librustuv/uvio.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use libc::c_int;
2222
use libc::{O_CREAT, O_APPEND, O_TRUNC, O_RDWR, O_RDONLY, O_WRONLY, S_IRUSR,
2323
S_IWUSR};
2424
use libc;
25-
use std::path::Path;
2625
use std::rt::rtio;
2726
use std::rt::rtio::{ProcessConfig, IoFactory, EventLoop};
2827
use ai = std::io::net::addrinfo;
@@ -241,7 +240,7 @@ impl IoFactory for UvIoFactory {
241240
r.map_err(uv_error_to_io_error)
242241
}
243242
fn fs_readdir(&mut self, path: &CString, flags: c_int)
244-
-> Result<Vec<Path>, IoError>
243+
-> Result<Vec<CString>, IoError>
245244
{
246245
let r = FsRequest::readdir(&self.loop_, path, flags);
247246
r.map_err(uv_error_to_io_error)
@@ -258,7 +257,7 @@ impl IoFactory for UvIoFactory {
258257
let r = FsRequest::chown(&self.loop_, path, uid, gid);
259258
r.map_err(uv_error_to_io_error)
260259
}
261-
fn fs_readlink(&mut self, path: &CString) -> Result<Path, IoError> {
260+
fn fs_readlink(&mut self, path: &CString) -> Result<CString, IoError> {
262261
let r = FsRequest::readlink(&self.loop_, path);
263262
r.map_err(uv_error_to_io_error)
264263
}

src/libstd/io/fs.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,9 @@ pub fn symlink(src: &Path, dst: &Path) -> IoResult<()> {
410410
/// This function will return an error on failure. Failure conditions include
411411
/// reading a file that does not exist or reading a file which is not a symlink.
412412
pub fn readlink(path: &Path) -> IoResult<Path> {
413-
LocalIo::maybe_raise(|io| io.fs_readlink(&path.to_c_str()))
413+
LocalIo::maybe_raise(|io| {
414+
Ok(Path::new(try!(io.fs_readlink(&path.to_c_str()))))
415+
})
414416
}
415417

416418
/// Create a new, empty directory at the provided path
@@ -487,7 +489,9 @@ pub fn rmdir(path: &Path) -> IoResult<()> {
487489
/// file
488490
pub fn readdir(path: &Path) -> IoResult<Vec<Path>> {
489491
LocalIo::maybe_raise(|io| {
490-
io.fs_readdir(&path.to_c_str(), 0)
492+
Ok(try!(io.fs_readdir(&path.to_c_str(), 0)).move_iter().map(|a| {
493+
Path::new(a)
494+
}).collect())
491495
})
492496
}
493497

src/libstd/rt/rtio.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use mem;
1919
use ops::Drop;
2020
use option::{Option, Some, None};
2121
use owned::Box;
22-
use path::Path;
2322
use result::Err;
2423
use rt::local::Local;
2524
use rt::task::Task;
@@ -223,11 +222,11 @@ pub trait IoFactory {
223222
fn fs_rmdir(&mut self, path: &CString) -> IoResult<()>;
224223
fn fs_rename(&mut self, path: &CString, to: &CString) -> IoResult<()>;
225224
fn fs_readdir(&mut self, path: &CString, flags: c_int) ->
226-
IoResult<Vec<Path>>;
225+
IoResult<Vec<CString>>;
227226
fn fs_lstat(&mut self, path: &CString) -> IoResult<FileStat>;
228227
fn fs_chown(&mut self, path: &CString, uid: int, gid: int) ->
229228
IoResult<()>;
230-
fn fs_readlink(&mut self, path: &CString) -> IoResult<Path>;
229+
fn fs_readlink(&mut self, path: &CString) -> IoResult<CString>;
231230
fn fs_symlink(&mut self, src: &CString, dst: &CString) -> IoResult<()>;
232231
fn fs_link(&mut self, src: &CString, dst: &CString) -> IoResult<()>;
233232
fn fs_utime(&mut self, src: &CString, atime: u64, mtime: u64) ->

0 commit comments

Comments
 (0)