pub struct OpenOptions { /* private fields */ }std only.Expand description
Options to open a file with async path-traversal protection.
Mirrors the access-mode setters of tokio::fs::OpenOptions
(read/write/append/truncate/create/create_new) and adds
jail to confine every opened path to a trusted root
directory.
Implementations§
Source§impl OpenOptions
impl OpenOptions
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new set of options with every flag disabled, matching
tokio::fs::OpenOptions::new. Enable at least one access mode (e.g.
read) before calling open.
Sourcepub fn truncate(&mut self, truncate: bool) -> &mut Self
pub fn truncate(&mut self, truncate: bool) -> &mut Self
Set the option for truncating a previous file.
Sourcepub fn create(&mut self, create: bool) -> &mut Self
pub fn create(&mut self, create: bool) -> &mut Self
Set the option to create a new file, or open it if it already exists.
Sourcepub fn create_new(&mut self, create_new: bool) -> &mut Self
pub fn create_new(&mut self, create_new: bool) -> &mut Self
Set the option to create a new file, failing if it already exists.
Sourcepub fn jail(&mut self, root: impl Into<PathBuf>) -> &mut Self
pub fn jail(&mut self, root: impl Into<PathBuf>) -> &mut Self
Confine every opened path to within root.
The path passed to open is then interpreted as relative
to root; absolute paths are rejected, and the resolved path must remain
within root or the open fails with UnsafePathError::EscapesRoot.
root must exist when opening.
Sourcepub fn symlinks(&mut self, policy: SymlinkPolicy) -> &mut Self
pub fn symlinks(&mut self, policy: SymlinkPolicy) -> &mut Self
Set how symbolic links are treated within the jail root.
Defaults to SymlinkPolicy::RestrictToRoot. Has no effect unless a
jail root is configured.
Sourcepub fn created_file_permissions(
&mut self,
permissions: CreatedFilePermissions,
) -> &mut Self
pub fn created_file_permissions( &mut self, permissions: CreatedFilePermissions, ) -> &mut Self
Set permissions used when this open operation creates a new file.