Patching bundles with new entries for fmt1 and fmt3 formats now results in new entries appended to the end
Publish PHP Package / docker (push) Successful in 6s Details

This commit is contained in:
Pavel Shevaev 2025-05-12 20:56:38 +03:00
parent 9ed9a4f7d9
commit 4c482ee26f
1 changed files with 47 additions and 4 deletions

View File

@ -164,7 +164,7 @@ function _config_pack_bundle_fmt1(
$strid_crc = crc32($entry->strid);
if(isset($STRIDMAP[$strid_crc]))
throw new Exception("Duplicating config str id crc for '{$entry->strid}' conflicts with '{$STRIDMAP[$strid_crc]}'");
throw new Exception("Duplicating config strid CRC for '{$entry->strid}' conflicts with '{$STRIDMAP[$strid_crc]}'");
$STRIDMAP[$strid_crc] = $entry->strid;
$header[] = array(
@ -294,7 +294,7 @@ function _config_pack_bundle_fmt3(
$strid_crc = crc32($entry->strid);
if(isset($STRIDMAP[$strid_crc]))
throw new Exception("Duplicating config str id crc for '{$entry->strid}' conflicts with '{$STRIDMAP[$strid_crc]}'");
throw new Exception("Duplicating config strid CRC for '{$entry->strid}' conflicts with '{$STRIDMAP[$strid_crc]}'");
$STRIDMAP[$strid_crc] = $entry->strid;
$header[] = array(
@ -399,7 +399,23 @@ function _config_patch_bundle_fmt1(
}
}
else
throw new Exception("Patched entry {$patch_entry->id} not found in config bundle");
{
//just append new entry to the end
$strid_crc32 = crc32($patch_entry->strid);
if(array_filter($header, fn($item) => $item[2] == $strid_crc32))
throw new Exception("Conflicting CRC for strid: $patch_entry->strid ($strid_crc32)");
$header[] = array(
$patch_format,
$patch_entry->id,
$strid_crc32,
$patch_entry->class_id,
strlen($payloads_bundle),
strlen($patch_payload)
);
$payloads_bundle .= $patch_payload;
}
}
$header_msgpack = config_msgpack_pack($header);
@ -544,11 +560,13 @@ function _config_patch_bundle_fmt3(
if(strlen($patch_payload_lz4) <= $lz4_chunk_size)
{
$payloads_bundle = substr_replace($payloads_bundle, $patched_chunk, $chunk_offset, strlen($patched_chunk));
$header_entry[0] = $patch_format;
$header_entry[6] = strlen($patch_payload);
}
//just append to the end
else
{
$header_entry[0] = $patch_format;
$header_entry[4] = strlen($payloads_bundle); //chunk offset
$header_entry[5] = 0;
$header_entry[6] = strlen($patch_payload);
@ -559,6 +577,7 @@ function _config_patch_bundle_fmt3(
//just append to the end
else
{
$header_entry[0] = $patch_format;
$header_entry[4] = strlen($payloads_bundle); //chunk offset
$header_entry[5] = 0;
$header_entry[6] = strlen($patch_payload);
@ -569,7 +588,31 @@ function _config_patch_bundle_fmt3(
$header[$header_idx] = $header_entry;
}
else
throw new Exception("Patched entry {$patch_entry->id} not found in config bundle");
{
//just append new entry to the end
$strid_crc32 = crc32($patch_entry->strid);
if(array_filter($header, fn($item) => $item[2] == $strid_crc32))
throw new Exception("Conflicting CRC for strid: $patch_entry->strid ($strid_crc32)");
//chunk contains only one patch entry
$patch_payload_lz4 = lz4_compress($patch_payload, 9);
$patched_chunk = pack("V", strlen($patch_payload_lz4));
$patched_chunk .= $patch_payload_lz4;
if(strlen($patch_payload) > $max_chunk_size)
$max_chunk_size = strlen($patch_payload);
$header[] = array(
$patch_format,
$patch_entry->id,
$strid_crc32,
$patch_entry->class_id,
strlen($payloads_bundle),
0,
strlen($patch_payload)
);
$payloads_bundle .= $patched_chunk;
}
}
$header_msgpack = config_msgpack_pack($header);