diff options
| author | Peter Atashian <retep998@gmail.com> | 2015-07-20 13:24:34 -0400 |
|---|---|---|
| committer | Peter Atashian <retep998@gmail.com> | 2015-07-20 13:24:34 -0400 |
| commit | 1e79917bda90d3b7ea53fc08b0c0c4862dfdca53 (patch) | |
| tree | 92539f2019d30946d1650a09847b1bf9dd9ce0cc /src/libstd | |
| parent | 32a12c8dd080034d0242958716de37beb2a67ab5 (diff) | |
| download | rust-1e79917bda90d3b7ea53fc08b0c0c4862dfdca53.tar.gz rust-1e79917bda90d3b7ea53fc08b0c0c4862dfdca53.zip | |
Improve Debug impl for File on Windows
Adds a path field if a path could be obtained Signed-off-by: Peter Atashian <retep998@gmail.com>
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/sys/windows/fs.rs | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index 890cc455d5d..424d24ea620 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -369,10 +369,13 @@ impl FromInner<libc::HANDLE> for File { 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() } } @@ -582,11 +585,7 @@ pub fn utimes(p: &Path, atime: u64, mtime: u64) -> io::Result<()> { 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) @@ -595,6 +594,13 @@ pub fn canonicalize(p: &Path) -> io::Result<PathBuf> { }) } +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, |
