MCPcopy Index your code
hub / github.com/AI45Lab/Code / load_from_dir_with_limits

Method load_from_dir_with_limits

core/src/tools/artifacts.rs:130–148  ·  view source on GitHub ↗
(
        dir: impl AsRef<Path>,
        limits: ArtifactStoreLimits,
    )

Source from the content-addressed store, hash-verified

128 }
129
130 pub fn load_from_dir_with_limits(
131 dir: impl AsRef<Path>,
132 limits: ArtifactStoreLimits,
133 ) -> Result<Self> {
134 let path = artifact_manifest_path(dir.as_ref());
135 if !path.exists() {
136 return Ok(Self::with_limits(limits));
137 }
138
139 let json = std::fs::read_to_string(&path)
140 .with_context(|| format!("failed to read artifact manifest '{}'", path.display()))?;
141 let snapshot: ArtifactStoreSnapshot =
142 serde_json::from_str(&json).context("failed to parse artifact store snapshot")?;
143 let store = Self::with_limits(limits);
144 for artifact in snapshot.artifacts {
145 store.put(artifact);
146 }
147 Ok(store)
148 }
149
150 fn enforce_limits(&self, state: &mut ArtifactStoreState) {
151 while state.artifacts.len() > self.limits.max_artifacts

Callers

nothing calls this directly

Calls 5

artifact_manifest_pathFunction · 0.85
with_contextMethod · 0.80
contextMethod · 0.80
putMethod · 0.80
existsMethod · 0.45

Tested by

no test coverage detected