Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
retep998 committed Jul 20, 2015
1 parent 32a12c8 commit 1e79917
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/libstd/sys/windows/fs.rs
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit 1e79917

Please sign in to comment.