about summary refs log tree commit diff
path: root/src/librustuv
diff options
context:
space:
mode:
authorYuri Kunde Schlesner <yuriks@yuriks.net>2014-05-12 02:31:22 -0300
committerAlex Crichton <alex@alexcrichton.com>2014-05-12 19:52:29 -0700
commit8c55fcd1f2ef3674d4bda4e38e2e7cacdd7cd5b8 (patch)
tree26e430f86234c4be047df9369327942a4d0861c7 /src/librustuv
parentf096516d2b5e0ac1a634742a11520dff4b59014b (diff)
downloadrust-8c55fcd1f2ef3674d4bda4e38e2e7cacdd7cd5b8.tar.gz
rust-8c55fcd1f2ef3674d4bda4e38e2e7cacdd7cd5b8.zip
Add `stat` method to `std::io::fs::File` to stat without a Path.
The `FileStat` struct contained a `path` field, which was filled by the
`stat` and `lstat` function. Since this field isn't in fact returned by
the operating system (it was copied from the paths passed to the
functions) it was removed, as in the `fstat` case we aren't working with
a `Path`, but directly with a fd.

If your code used the `path` field of `FileStat` you will now have to
manually store the path passed to `stat` along with the returned struct.

[breaking-change]
Diffstat (limited to 'src/librustuv')
-rw-r--r--src/librustuv/file.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/librustuv/file.rs b/src/librustuv/file.rs
index cd56e76aff6..06271e61ce7 100644
--- a/src/librustuv/file.rs
+++ b/src/librustuv/file.rs
@@ -70,6 +70,12 @@ impl FsRequest {
         }).map(|req| req.mkstat())
     }
 
+    pub fn fstat(loop_: &Loop, fd: c_int) -> Result<FileStat, UvError> {
+        execute(|req, cb| unsafe {
+            uvll::uv_fs_fstat(loop_.handle, req, fd, cb)
+        }).map(|req| req.mkstat())
+    }
+
     pub fn write(loop_: &Loop, fd: c_int, buf: &[u8], offset: i64)
         -> Result<(), UvError>
     {
@@ -262,8 +268,6 @@ impl FsRequest {
     }
 
     pub fn mkstat(&self) -> FileStat {
-        let path = unsafe { uvll::get_path_from_fs_req(self.req) };
-        let path = unsafe { Path::new(CString::new(path, false)) };
         let stat = self.get_stat();
         fn to_msec(stat: uvll::uv_timespec_t) -> u64 {
             // Be sure to cast to u64 first to prevent overflowing if the tv_sec
@@ -279,7 +283,6 @@ impl FsRequest {
             _ => io::TypeUnknown,
         };
         FileStat {
-            path: path,
             size: stat.st_size as u64,
             kind: kind,
             perm: unsafe {
@@ -463,6 +466,11 @@ impl rtio::RtioFileStream for FileWatcher {
         let r = FsRequest::truncate(&self.loop_, self.fd, offset);
         r.map_err(uv_error_to_io_error)
     }
+
+    fn fstat(&mut self) -> Result<FileStat, IoError> {
+        let _m = self.fire_homing_missile();
+        FsRequest::fstat(&self.loop_, self.fd).map_err(uv_error_to_io_error)
+    }
 }
 
 #[cfg(test)]
@@ -537,6 +545,10 @@ mod test {
         assert!(result.is_ok());
         assert_eq!(result.unwrap().size, 5);
 
+        let result = FsRequest::fstat(l(), file.fd);
+        assert!(result.is_ok());
+        assert_eq!(result.unwrap().size, 5);
+
         fn free<T>(_: T) {}
         free(file);