1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use super::internal_open;
use crate::fs::{canonicalize_options, FollowSymlinks, MaybeOwnedFile};
use std::path::{Path, PathBuf};
use std::{fs, io};
pub(crate) fn canonicalize(start: &fs::File, path: &Path) -> io::Result<PathBuf> {
canonicalize_with(start, path, FollowSymlinks::Yes)
}
pub(crate) fn canonicalize_with(
start: &fs::File,
path: &Path,
follow: FollowSymlinks,
) -> io::Result<PathBuf> {
let mut symlink_count = 0;
let mut canonical_path = PathBuf::new();
let start = MaybeOwnedFile::borrowed(start);
if let Err(e) = internal_open(
start,
path,
canonicalize_options().follow(follow),
&mut symlink_count,
Some(&mut canonical_path),
) {
if canonical_path.as_os_str().is_empty() {
return Err(e);
}
}
Ok(canonical_path)
}