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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use std::ffi::OsStr;
use std::path::{Component, PathBuf};
pub(super) struct CanonicalPath<'path_buf> {
path: Option<&'path_buf mut PathBuf>,
#[cfg(racy_asserts)]
pub(super) debug: PathBuf,
}
impl<'path_buf> CanonicalPath<'path_buf> {
pub(super) fn new(path: Option<&'path_buf mut PathBuf>) -> Self {
Self {
#[cfg(racy_asserts)]
debug: PathBuf::new(),
path,
}
}
pub(super) fn push(&mut self, one: &OsStr) {
#[cfg(racy_asserts)]
self.debug.push(one);
if let Some(path) = &mut self.path {
path.push(one)
}
}
pub(super) fn pop(&mut self) -> bool {
#[cfg(racy_asserts)]
self.debug.pop();
if let Some(path) = &mut self.path {
path.pop()
} else {
true
}
}
pub(super) fn complete(&mut self) {
if let Some(path) = &mut self.path {
if path.as_os_str().is_empty() {
path.push(Component::CurDir);
}
self.path = None;
}
}
}
impl<'path_buf> Drop for CanonicalPath<'path_buf> {
fn drop(&mut self) {
if let Some(path) = &mut self.path {
path.clear();
self.path = None;
}
}
}