Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Debug impl for File on Windows #27150

Merged
merged 1 commit into from
Jul 21, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/libstd/sys/windows/fs.rs
Original file line number Diff line number Diff line change
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