Compare commits

..

4 Commits

Author SHA1 Message Date
Pavel Shevaev 20eefabac8 Newly added files are always marked as affected
Publish PHP Package / docker (push) Successful in 6s Details
2025-05-14 19:36:29 +03:00
Pavel Shevaev df8a59f15b Newly added files are also supported for patching now
Publish PHP Package / docker (push) Successful in 6s Details
2025-05-14 17:03:02 +03:00
Pavel Shevaev 4c482ee26f 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
2025-05-12 20:56:39 +03:00
Pavel Shevaev 9ed9a4f7d9 Making PHPStan happy
Publish PHP Package / docker (push) Successful in 6s Details
2025-05-07 17:51:10 +03:00
3 changed files with 65 additions and 13 deletions

View File

@ -461,8 +461,8 @@ function _config_merge_update_results(ConfigUpdateResult $result, array $results
$result->fast_jsons = $total_fast_jsons; $result->fast_jsons = $total_fast_jsons;
} }
function _config_update_cache_entry(ConfigGlobals $globals, $base_dir, string $file, string $cache_file, function _config_update_cache_entry(ConfigGlobals $globals, $base_dir, string $file,
?int &$parser_type = null) : ConfigCacheEntry string $cache_file, ?int &$parser_type = null) : ConfigCacheEntry
{ {
list($conf_id, $conf_strid) = config_ensure_header($base_dir, $file); list($conf_id, $conf_strid) = config_ensure_header($base_dir, $file);
if(!$conf_id) if(!$conf_id)

View File

@ -134,7 +134,7 @@ class ConfigUpdateResult
{ {
return ($this->request->mode == ConfigUpdateMode::Selected || return ($this->request->mode == ConfigUpdateMode::Selected ||
$this->request->mode === ConfigUpdateMode::DetectChanged) && $this->request->mode === ConfigUpdateMode::DetectChanged) &&
count(array_filter($this->added_files, fn($f) => config_is_file($f))) == 0 && //TODO: support removed files as well?
count(array_filter($this->removed_files, fn($f) => config_is_file($f))) == 0; count(array_filter($this->removed_files, fn($f) => config_is_file($f))) == 0;
} }
} }
@ -315,18 +315,18 @@ class ConfigManager
{ {
$fs_cache_map = $this->getFileMap(); $fs_cache_map = $this->getFileMap();
if($req->mode === ConfigUpdateMode::Force) if($req->mode == ConfigUpdateMode::Force)
{ {
//let's rebuild the file map //let's rebuild the file map
$fs_cache_map->init($req->files->getAllFiles()); $fs_cache_map->init($req->files->getAllFiles());
config_log("File map init: ".$fs_cache_map->count()); config_log("File map init: ".$fs_cache_map->count());
} }
else if($req->mode === ConfigUpdateMode::DetectChanged) else if($req->mode == ConfigUpdateMode::DetectChanged)
{ {
list($added_files, $removed_files) = $fs_cache_map->compare($req->files->getAllFiles()); list($added_files, $removed_files) = $fs_cache_map->compare($req->files->getAllFiles());
config_log("File map compare, added: ".count($added_files).", removed: ".count($removed_files)); config_log("File map compare, added: ".count($added_files).", removed: ".count($removed_files));
} }
else if($req->mode === ConfigUpdateMode::Selected) else if($req->mode == ConfigUpdateMode::Selected)
{ {
if($req->file_changes != null) if($req->file_changes != null)
{ {
@ -339,6 +339,8 @@ class ConfigManager
} }
} }
} }
else
throw new Exception("Bad mode");
} }
private function _updateFileMap(ConfigUpdateRequest $req, ConfigDirFiles $affected_conf_files, array $added_files, array $removed_files) private function _updateFileMap(ConfigUpdateRequest $req, ConfigDirFiles $affected_conf_files, array $added_files, array $removed_files)
@ -368,11 +370,11 @@ class ConfigManager
$affected_files = null; $affected_files = null;
if($req->mode === ConfigUpdateMode::Force) if($req->mode == ConfigUpdateMode::Force)
{ {
$affected_files = new ConfigDirFiles($req->files->getMap()); $affected_files = new ConfigDirFiles($req->files->getMap());
} }
else if($req->mode === ConfigUpdateMode::DetectChanged) else if($req->mode == ConfigUpdateMode::DetectChanged)
{ {
$affected_files = ConfigDirFiles::makeFor($this); $affected_files = ConfigDirFiles::makeFor($this);
@ -393,6 +395,11 @@ class ConfigManager
} }
} }
//NOTE: newly added files are marked as affected always without checking for staleness
// with the last run file
foreach($added_files as $file)
$affected_files->addFile($file, unique: true);
//if there were removed files we need to rebuild affected files //if there were removed files we need to rebuild affected files
foreach($removed_files as $file) foreach($removed_files as $file)
{ {
@ -401,7 +408,7 @@ class ConfigManager
$affected_files->addFile($dep, unique: true); $affected_files->addFile($dep, unique: true);
} }
} }
else if($req->mode === ConfigUpdateMode::Selected) else if($req->mode == ConfigUpdateMode::Selected)
{ {
$affected_files = ConfigDirFiles::makeFor($this); $affected_files = ConfigDirFiles::makeFor($this);
@ -413,6 +420,8 @@ class ConfigManager
$affected_files->addFile($dep, unique: true); $affected_files->addFile($dep, unique: true);
} }
} }
else
throw new Exception("Bad mode");
return $affected_files; return $affected_files;
} }

View File

@ -164,7 +164,7 @@ function _config_pack_bundle_fmt1(
$strid_crc = crc32($entry->strid); $strid_crc = crc32($entry->strid);
if(isset($STRIDMAP[$strid_crc])) 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; $STRIDMAP[$strid_crc] = $entry->strid;
$header[] = array( $header[] = array(
@ -294,7 +294,7 @@ function _config_pack_bundle_fmt3(
$strid_crc = crc32($entry->strid); $strid_crc = crc32($entry->strid);
if(isset($STRIDMAP[$strid_crc])) 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; $STRIDMAP[$strid_crc] = $entry->strid;
$header[] = array( $header[] = array(
@ -399,7 +399,23 @@ function _config_patch_bundle_fmt1(
} }
} }
else 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); $header_msgpack = config_msgpack_pack($header);
@ -544,11 +560,13 @@ function _config_patch_bundle_fmt3(
if(strlen($patch_payload_lz4) <= $lz4_chunk_size) if(strlen($patch_payload_lz4) <= $lz4_chunk_size)
{ {
$payloads_bundle = substr_replace($payloads_bundle, $patched_chunk, $chunk_offset, strlen($patched_chunk)); $payloads_bundle = substr_replace($payloads_bundle, $patched_chunk, $chunk_offset, strlen($patched_chunk));
$header_entry[0] = $patch_format;
$header_entry[6] = strlen($patch_payload); $header_entry[6] = strlen($patch_payload);
} }
//just append to the end //just append to the end
else else
{ {
$header_entry[0] = $patch_format;
$header_entry[4] = strlen($payloads_bundle); //chunk offset $header_entry[4] = strlen($payloads_bundle); //chunk offset
$header_entry[5] = 0; $header_entry[5] = 0;
$header_entry[6] = strlen($patch_payload); $header_entry[6] = strlen($patch_payload);
@ -559,6 +577,7 @@ function _config_patch_bundle_fmt3(
//just append to the end //just append to the end
else else
{ {
$header_entry[0] = $patch_format;
$header_entry[4] = strlen($payloads_bundle); //chunk offset $header_entry[4] = strlen($payloads_bundle); //chunk offset
$header_entry[5] = 0; $header_entry[5] = 0;
$header_entry[6] = strlen($patch_payload); $header_entry[6] = strlen($patch_payload);
@ -569,7 +588,31 @@ function _config_patch_bundle_fmt3(
$header[$header_idx] = $header_entry; $header[$header_idx] = $header_entry;
} }
else 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); $header_msgpack = config_msgpack_pack($header);