Introduce FsPathFollow

Make sure all operations of FsPath do not follow symlinks, and provide
a way to explicitly switch over to a set of operations that DO follow
symlinks by FsPath::follow_link.
This commit is contained in:
topjohnwu
2025-03-07 02:36:08 -08:00
committed by John Wu
parent c64de35375
commit 6ff82c4e86
5 changed files with 526 additions and 431 deletions

View File

@@ -501,6 +501,25 @@ impl DerefMut for FsPath {
}
}
#[repr(transparent)]
pub struct FsPathFollow(Utf8CStr);
impl Deref for FsPathFollow {
type Target = Utf8CStr;
#[inline(always)]
fn deref(&self) -> &Utf8CStr {
&self.0
}
}
impl DerefMut for FsPathFollow {
#[inline(always)]
fn deref_mut(&mut self) -> &mut Utf8CStr {
&mut self.0
}
}
enum Utf8CStrBufOwned<const N: usize> {
Dynamic(Utf8CString),
Fixed(Utf8CStrBufArr<N>),
@@ -667,6 +686,7 @@ macro_rules! impl_str {
impl_str!(
(Utf8CStr,)
(FsPath,)
(FsPathFollow,)
(FsPathBuf<N>, const N: usize)
(Utf8CStrBufRef<'_>,)
(Utf8CStrBufArr<N>, const N: usize)