Skip to main content

workyard_state/
reader.rs

1//! Existing-only state reader; observations never enter mutation admission.
2mod coordination;
3mod history;
4mod snapshot;
5mod task;
6mod validation;
7use crate::{Lock, workspace::Workspace};
8use std::path::{Path, PathBuf};
9use workyard_core::Problem;
10
11/// Shared read access to an existing workspace and its task records.
12pub struct Reader {
13	pub(crate) root: PathBuf,
14	pub(crate) state: PathBuf,
15	gate: Lock,
16}
17
18impl Reader {
19	/// Open the selected workspace and verify its binding.
20	pub fn open(state: &Path, requested_root: Option<&Path>) -> Result<Self, Problem> {
21		let workspace = Workspace::open(state, requested_root)?;
22		Ok(Self {
23			root: workspace.root,
24			state: workspace.state,
25			gate: workspace.gate,
26		})
27	}
28
29	/// Return the directory containing the task workspaces.
30	pub fn root(&self) -> &Path {
31		&self.root
32	}
33
34	/// Return the workspace state directory.
35	pub fn state(&self) -> &Path {
36		&self.state
37	}
38
39	pub(crate) fn verify(&self) -> Result<(), Problem> {
40		Workspace::verify(&self.state, &self.root, &self.gate)
41	}
42}