Skip to main content

prov_graph/graph/
probe.rs

1//! Raw filesystem probes — root-join and delegate, nothing else.
2//!
3//! Distinct from [`load`](super::load): these do not clamp against root
4//! escape, do not consult or populate the read-scope memo, and (for
5//! [`read_bytes`](Graph::read_bytes)/[`read_text`](Graph::read_text))
6//! do not parse. They exist so that every module outside `graph` reaches the
7//! filesystem through `Workspace` rather than holding a [`ReadStorage`] handle of
8//! its own — see the module doc at [`crate::graph`]. A caller that needs the
9//! clamp (any path that can originate in a document's own metadata) wants
10//! [`load`](super::load) instead.
11
12use std::path::Path;
13
14use super::Graph;
15use crate::error::Result;
16use crate::fs::{DirEntry, Metadata, ReadStorage};
17
18impl<FS: ReadStorage, Ix> Graph<FS, Ix> {
19    /// Whether the workspace-relative `path` exists. Mirrors
20    /// [`ReadStorage::try_exists`], joined to the workspace root.
21    pub async fn exists(&self, path: &Path) -> Result<bool> {
22        Ok(self.fs().try_exists(&self.root().join(path)).await?)
23    }
24
25    /// Read the entire contents of the workspace-relative `path` as bytes.
26    /// Mirrors [`ReadStorage::read`], joined to the workspace root.
27    pub async fn read_bytes(&self, path: &Path) -> Result<Vec<u8>> {
28        Ok(self.fs().read(&self.root().join(path)).await?)
29    }
30
31    /// Read the entire contents of the workspace-relative `path` as a
32    /// string. Mirrors [`ReadStorage::read_to_string`], joined to the workspace
33    /// root.
34    pub async fn read_text(&self, path: &Path) -> Result<String> {
35        Ok(self.fs().read_to_string(&self.root().join(path)).await?)
36    }
37
38    /// List the entries of the workspace-relative directory `path`. Mirrors
39    /// [`ReadStorage::read_dir`], joined to the workspace root.
40    pub async fn listing(&self, path: &Path) -> Result<Vec<DirEntry>> {
41        Ok(self.fs().read_dir(&self.root().join(path)).await?)
42    }
43
44    /// Metadata about the entry at the workspace-relative `path`. Mirrors
45    /// [`ReadStorage::metadata`], joined to the workspace root.
46    pub async fn stat(&self, path: &Path) -> Result<Metadata> {
47        Ok(self.fs().metadata(&self.root().join(path)).await?)
48    }
49}