@@ -594,6 +594,53 @@ pub fn write_manifest<ObjectID: FsVerityHashValue>(
594594 Ok ( ( manifest_digest. to_string ( ) , id) )
595595}
596596
597+ /// Writes a manifest to the repository from raw JSON bytes.
598+ ///
599+ /// Unlike [`write_manifest`], this preserves the exact JSON bytes from the
600+ /// original source, avoiding digest mismatches from re-serialization.
601+ pub fn write_manifest_raw < ObjectID : FsVerityHashValue > (
602+ repo : & Arc < Repository < ObjectID > > ,
603+ manifest_json : & [ u8 ] ,
604+ manifest_digest : & str ,
605+ config_verity : & ObjectID ,
606+ layer_verities : & HashMap < Box < str > , ObjectID > ,
607+ reference : Option < & str > ,
608+ ) -> Result < ( String , ObjectID ) > {
609+ let content_id = manifest_identifier ( manifest_digest) ;
610+
611+ if let Some ( verity) = repo. has_stream ( & content_id) ? {
612+ if let Some ( name) = reference {
613+ tag_image ( repo, manifest_digest, name) ?;
614+ }
615+ return Ok ( ( manifest_digest. to_string ( ) , verity) ) ;
616+ }
617+
618+ let computed = hash ( manifest_json) ;
619+ ensure ! (
620+ manifest_digest == computed,
621+ "Manifest digest mismatch: expected {manifest_digest}, got {computed}"
622+ ) ;
623+
624+ let manifest: ImageManifest =
625+ serde_json:: from_slice ( manifest_json) . context ( "parsing manifest JSON" ) ?;
626+
627+ let mut stream = repo. create_stream ( OCI_MANIFEST_CONTENT_TYPE ) ;
628+
629+ let config_key = format ! ( "config:{}" , manifest. config( ) . digest( ) ) ;
630+ stream. add_named_stream_ref ( & config_key, config_verity) ;
631+
632+ for ( diff_id, verity) in layer_verities {
633+ stream. add_named_stream_ref ( diff_id, verity) ;
634+ }
635+
636+ stream. write_external ( manifest_json) ?;
637+
638+ let oci_ref = reference. map ( oci_ref_path) ;
639+ let id = repo. write_stream ( stream, & content_id, oci_ref. as_deref ( ) ) ?;
640+
641+ Ok ( ( manifest_digest. to_string ( ) , id) )
642+ }
643+
597644/// Checks if a manifest exists.
598645pub fn has_manifest < ObjectID : FsVerityHashValue > (
599646 repo : & Repository < ObjectID > ,
0 commit comments