impl fmt::Debug for File {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- // FIXME(#24570): add more info here (e.g. path, mode)
- f.debug_struct("File")
- .field("handle", &self.handle.raw())
- .finish()
+ // FIXME(#24570): add more info here (e.g. mode)
+ let mut b = f.debug_struct("File");
+ b.field("handle", &self.handle.raw());
+ if let Ok(path) = get_path(&self) {
+ b.field("path", &path);
+ }
+ b.finish()
}
}
Ok(())
}
-pub fn canonicalize(p: &Path) -> io::Result<PathBuf> {
-
- let mut opts = OpenOptions::new();
- opts.read(true);
- let f = try!(File::open(p, &opts));
+fn get_path(f: &File) -> io::Result<PathBuf> {
super::fill_utf16_buf(|buf, sz| unsafe {
c::GetFinalPathNameByHandleW(f.handle.raw(), buf, sz,
libc::VOLUME_NAME_DOS)
})
}
+pub fn canonicalize(p: &Path) -> io::Result<PathBuf> {
+ let mut opts = OpenOptions::new();
+ opts.read(true);
+ let f = try!(File::open(p, &opts));
+ get_path(&f)
+}
+
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
unsafe extern "system" fn callback(
_TotalFileSize: libc::LARGE_INTEGER,