pub struct ScopedDirBuilder { /* private fields */ }
Expand description
Safe version of DirBuilder
to protect from TOCTOU style of attacks.
The ScopedDirBuilder
is a counterpart for DirBuilder
, with safety enhancements of:
- ensuring the new directories are created under a specified
root
directory. - ensuring all created directories are still scoped under
root
even under symlink based attacks. - returning a PinnedPathBuf for the last level of directory, so it could be used for other operations safely.
Implementations§
Source§impl ScopedDirBuilder
impl ScopedDirBuilder
Sourcepub fn new<P: AsRef<Path>>(root: P) -> Result<Self>
pub fn new<P: AsRef<Path>>(root: P) -> Result<Self>
Create a new instance of ScopedDirBuilder
with with default mode/security settings.
Sourcepub fn recursive(&mut self, recursive: bool) -> &mut Self
pub fn recursive(&mut self, recursive: bool) -> &mut Self
Indicates that directories should be created recursively, creating all parent directories.
Parents that do not exist are created with the same security and permissions settings.
Sourcepub fn mode(&mut self, mode: u32) -> &mut Self
pub fn mode(&mut self, mode: u32) -> &mut Self
Sets the mode to create new directories with. This option defaults to 0o755.
Sourcepub fn create_with_unscoped_path<P: AsRef<Path>>(
&self,
path: P,
) -> Result<PinnedPathBuf>
pub fn create_with_unscoped_path<P: AsRef<Path>>( &self, path: P, ) -> Result<PinnedPathBuf>
Creates the specified directory with the options configured in this builder.
This is a helper to create subdirectory with an absolute path, without stripping off
self.root
. So error will be returned if path does start with self.root
.
It is considered an error if the directory already exists unless recursive mode is enabled.