Add canonical helpers to model.rs
Intent: Introduce a single source of truth for the payload manifest relative path, a path-builder function, and a JSON decode function so that no call-site needs to duplicate this logic.
Affected files: crates/pikaci/src/model.rs
@@ -1,3 +1,6 @@
+use std::path::{Path, PathBuf};
+
+use anyhow::Context;
use serde::{Deserialize, Serialize};
@@ -1554,6 +1557,20 @@ pub struct PreparedOutputPayloadManifestRecord {
pub mounts: Vec<PreparedOutputPayloadMountRecord>,
}
+pub const PREPARED_OUTPUT_PAYLOAD_MANIFEST_RELATIVE_PATH: &str =
+ "share/pikaci/payload-manifest.json";
+
+pub fn prepared_output_payload_manifest_path(output_root: &Path) -> PathBuf {
+ output_root.join(PREPARED_OUTPUT_PAYLOAD_MANIFEST_RELATIVE_PATH)
+}
+
+pub fn decode_prepared_output_payload_manifest(
+ bytes: &[u8],
+ manifest_path: &Path,
+) -> anyhow::Result<PreparedOutputPayloadManifestRecord> {
+ serde_json::from_slice(bytes).with_context(|| format!("decode {}", manifest_path.display()))
+}
Three new public items are added directly below PreparedOutputPayloadManifestRecord in model.rs:
PREPARED_OUTPUT_PAYLOAD_MANIFEST_RELATIVE_PATH– a&strconstant holding"share/pikaci/payload-manifest.json". This was previously a localconstinrun.rsand an inline literal inincus.rs.prepared_output_payload_manifest_path(output_root)– joins the constant onto any output root, returning aPathBuf.decode_prepared_output_payload_manifest(bytes, manifest_path)– wrapsserde_json::from_slicewith ananyhowcontext that includes the manifest path in the error message.
New use imports for std::path::{Path, PathBuf} and anyhow::Context are added at the top of the file to support these additions.