| 109 | } |
| 110 | |
| 111 | pub fn save_to_dir(&self, dir: impl AsRef<Path>) -> Result<()> { |
| 112 | let dir = dir.as_ref(); |
| 113 | std::fs::create_dir_all(dir) |
| 114 | .with_context(|| format!("failed to create artifact directory '{}'", dir.display()))?; |
| 115 | let snapshot = ArtifactStoreSnapshot { |
| 116 | artifacts: self.ordered_artifacts(), |
| 117 | }; |
| 118 | let json = serde_json::to_string_pretty(&snapshot) |
| 119 | .context("failed to serialize artifact store snapshot")?; |
| 120 | let path = artifact_manifest_path(dir); |
| 121 | std::fs::write(&path, json) |
| 122 | .with_context(|| format!("failed to write artifact manifest '{}'", path.display()))?; |
| 123 | Ok(()) |
| 124 | } |
| 125 | |
| 126 | pub fn load_from_dir(dir: impl AsRef<Path>) -> Result<Self> { |
| 127 | Self::load_from_dir_with_limits(dir, ArtifactStoreLimits::default()) |