Skip to content

Commit

Permalink
Auto merge of #28729 - retep998:canonical-dir, r=alexcrichton
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Sep 30, 2015
2 parents 44d4048 + 6b9b2ee commit c459e89
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2083,6 +2083,15 @@ mod tests {
check!(fs::create_dir_all(&path.join("a/")));
}

#[test]
fn canonicalize_works_simple() {
let tmpdir = tmpdir();
let tmpdir = fs::canonicalize(tmpdir.path()).unwrap();
let file = tmpdir.join("test");
File::create(&file).unwrap();
assert_eq!(fs::canonicalize(&file).unwrap(), file);
}

#[test]
#[cfg(not(windows))]
fn realpath_works() {
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/sys/windows/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,8 @@ fn get_path(f: &File) -> io::Result<PathBuf> {
pub fn canonicalize(p: &Path) -> io::Result<PathBuf> {
let mut opts = OpenOptions::new();
opts.read(true);
// This flag is so we can open directories too
opts.flags_and_attributes(c::FILE_FLAG_BACKUP_SEMANTICS);
let f = try!(File::open(p, &opts));
get_path(&f)
}
Expand Down

0 comments on commit c459e89

Please sign in to comment.