pub struct WriteScope { /* private fields */ }Expand description
The directories a run may write into.
Implementations§
Source§impl WriteScope
impl WriteScope
Sourcepub fn new(
root: &Path,
cwd: &Path,
shared_dirs: Vec<PathBuf>,
) -> Result<Self, String>
pub fn new( root: &Path, cwd: &Path, shared_dirs: Vec<PathBuf>, ) -> Result<Self, String>
Build the scope for a project root.
The Git work tree that contains the root counts only when cwd is
inside it too. That is the monorepo case the allowance exists for. It
keeps a Git repository at $HOME (a dotfiles setup) from allowing
every home path to a run started outside that tree.
§Errors
Returns a message when the root cannot be resolved, so a caller fails closed.
Sourcepub fn contains(&self, path: &Path) -> bool
pub fn contains(&self, path: &Path) -> bool
Whether a write to the absolute path path, as written, stays in the
scope. See Self::check for the rules.
Sourcepub fn check(&self, flag: &str, path: &Path, cwd: &Path) -> Option<String>
pub fn check(&self, flag: &str, path: &Path, cwd: &Path) -> Option<String>
Return an error message when a write to path, relative to cwd,
leaves the scope. flag names the option that asked for the write.
- The path must resolve inside one of the allowed directories, or be an existing character device or named pipe.
- Each symlink on the way that lies in the project root or its Git work tree must resolve inside the root or the allowed work tree.
- No symlink on the way, wherever it lies, may resolve into a
.gitornode_modulesdirectory (fallow_types::path_guard::is_protected_link_target), or into the Git directory or common Git directory of the root, also when that directory is outside the work tree. A shared directory or a device is allowed only for a path that reaches it without such a link. - An existing target that is not a regular file or a directory is refused, except a character device or named pipe that is reached without such a link.
- A path component that cannot be read for a reason other than “not found” is refused.
Sourcepub fn refusal_reason(&self, path: &Path) -> Option<&'static str>
pub fn refusal_reason(&self, path: &Path) -> Option<&'static str>
Why a write to the absolute path path leaves the scope, as the end
of a sentence that starts with “resolves”, or None when it stays in
the scope.
Trait Implementations§
Source§impl Clone for WriteScope
impl Clone for WriteScope
Auto Trait Implementations§
impl Forget for WriteScope
impl Freeze for WriteScope
impl Move for WriteScope
impl RefUnwindSafe for WriteScope
impl Send for WriteScope
impl Sync for WriteScope
impl Unpin for WriteScope
impl UnsafeUnpin for WriteScope
impl UnwindSafe for WriteScope
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more