pub struct Workdir {
base: PathBuf,
canonical: PathBuf,
}Expand description
An agent’s working directory, resolved once.
Fields§
§base: PathBuf§canonical: PathBufImplementations§
Source§impl Workdir
impl Workdir
Sourcepub fn open(base: &Path) -> Result<Workdir>
pub fn open(base: &Path) -> Result<Workdir>
The workdir at base, which must already exist (callers create it).
Sourcepub fn base(&self) -> &Path
pub fn base(&self) -> &Path
The workdir’s own path, as given to Workdir::open.
Sourcepub fn resolve(&self, rel: &str) -> Result<PathBuf>
pub fn resolve(&self, rel: &str) -> Result<PathBuf>
rel inside the workdir, or a refusal: lexically outside it, under a
folder that links out of it, or a symlink itself (dangling or not).
Sourcefn ensure_parent(&self, path: &Path) -> Result<()>
fn ensure_parent(&self, path: &Path) -> Result<()>
The parent folder of a resolved path, created inside the workdir.
Sourcepub fn write(&self, rel: &str, bytes: &[u8], owner_only: bool) -> Result<()>
pub fn write(&self, rel: &str, bytes: &[u8], owner_only: bool) -> Result<()>
Replace rel with bytes, atomically. Parent folders are created
inside the workdir. owner_only makes the file 0600 on Unix (for
files holding keys, such as .mcp.json); otherwise a file being
replaced keeps its mode, as an in-place write would.
Sourcepub fn create_new(&self, rel: &str, bytes: &[u8]) -> Result<bool>
pub fn create_new(&self, rel: &str, bytes: &[u8]) -> Result<bool>
Create rel with bytes only if nothing is there: Ok(true) when
created, Ok(false) when it already existed. The file appears whole
or not at all, even across a crash: it is written and synced under a
temporary name, then hard-linked into place, which fails if rel
already exists (Codex on #4141 — a partial .pre-adopt backup would
otherwise block adoption forever).
Sourcepub fn append(&self, rel: &str, bytes: &[u8]) -> Result<()>
pub fn append(&self, rel: &str, bytes: &[u8]) -> Result<()>
Append bytes to an existing rel: a true append, never a rewrite,
so an edit racing the caller’s earlier read is kept.
Sourcepub fn remove_file(&self, rel: &str) -> Result<()>
pub fn remove_file(&self, rel: &str) -> Result<()>
Remove rel. The path is checked like a write, so a link to outside
the workdir is refused rather than removed.
Sourcepub fn remove_dir(&self, rel: &str) -> Result<()>
pub fn remove_dir(&self, rel: &str) -> Result<()>
Remove the empty folder rel.
Sourcepub fn open_lock_file(&self, rel: &str) -> Result<File>
pub fn open_lock_file(&self, rel: &str) -> Result<File>
Open rel for read/write, creating it if absent and never truncating
it: for lock files.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Workdir
impl RefUnwindSafe for Workdir
impl Send for Workdir
impl Sync for Workdir
impl Unpin for Workdir
impl UnsafeUnpin for Workdir
impl UnwindSafe for Workdir
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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