]> git.lizzy.rs Git - rust.git/commitdiff
rtio: Remove usage of `Path`
authorAlex Crichton <alex@alexcrichton.com>
Tue, 3 Jun 2014 05:11:19 +0000 (22:11 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sat, 7 Jun 2014 05:19:41 +0000 (22:19 -0700)
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.

src/libnative/io/file_unix.rs
src/libnative/io/file_win32.rs
src/libnative/io/mod.rs
src/librustuv/file.rs
src/librustuv/uvio.rs
src/libstd/io/fs.rs
src/libstd/rt/rtio.rs

index b10284a3b6c3f0da7b269c186667bf6cb803ac02..3182b061e5238fb8e1ded31d7b9b97c3836fd973 100644 (file)
@@ -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())
         }
     }
 }
index 4f1f3b3ca26f726374cbc7e3fcaaf57085da0389..2cf54ab4007c6a24e4170ffbf2329e6829e074b7 100644 (file)
@@ -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 {
index 240b87fda084d13e39110543d842ac9d9cfdf313..a17a683646a810942f042445bd7dacc5ba5c4ac0 100644 (file)
@@ -232,7 +232,7 @@ fn fs_rmdir(&mut self, path: &CString) -> IoResult<()> {
     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 @@ 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<()> {
index 7143f420b08a1b8c5bce0d685f0b1598da356f1c..acf3cbdc1aea02aea24a8799fb02fbc8b461c50b 100644 (file)
@@ -157,7 +157,7 @@ pub fn chmod(loop_: &Loop, path: &CString, mode: c_int)
     }
 
     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 @@ pub fn readdir(loop_: &Loop, path: &CString, flags: c_int)
                                               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()
+            }
         })
     }
 
index 71589e00fc008e5f08f68877a0e750be5db757d7..c55b5f64f9dc8b0e749af631dc69aea12cdb29cd 100644 (file)
@@ -22,7 +22,6 @@
 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 @@ fn fs_chmod(&mut self, path: &CString,
         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 @@ fn fs_chown(&mut self, path: &CString, uid: int, gid: int) -> Result<(), IoError
         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)
     }
index a77c7107f282f39785dbf5b795f58eed6f669eaf..96ab8989a2152c31bbe06cc5884f6317240d5cdc 100644 (file)
@@ -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())
     })
 }
 
index 24ff2a8f425980f7ee651abfeb3ec286ece84240..4b5ca6178a756c09985f50908b93f543fcba4212 100644 (file)
@@ -19,7 +19,6 @@
 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 @@ fn fs_chmod(&mut self, path: &CString,
     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) ->