Compare commits

..

No commits in common. "master" and "v6.2.0" have entirely different histories.

3 changed files with 13 additions and 65 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, function _config_update_cache_entry(ConfigGlobals $globals, $base_dir, string $file, string $cache_file,
string $cache_file, ?int &$parser_type = null) : ConfigCacheEntry ?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) &&
//TODO: support removed files as well? count(array_filter($this->added_files, fn($f) => config_is_file($f))) == 0 &&
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,8 +339,6 @@ 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)
@ -370,11 +368,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);
@ -395,11 +393,6 @@ 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)
{ {
@ -408,7 +401,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);
@ -420,8 +413,6 @@ 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 strid CRC for '{$entry->strid}' conflicts with '{$STRIDMAP[$strid_crc]}'"); throw new Exception("Duplicating config str id 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 strid CRC for '{$entry->strid}' conflicts with '{$STRIDMAP[$strid_crc]}'"); throw new Exception("Duplicating config str id crc for '{$entry->strid}' conflicts with '{$STRIDMAP[$strid_crc]}'");
$STRIDMAP[$strid_crc] = $entry->strid; $STRIDMAP[$strid_crc] = $entry->strid;
$header[] = array( $header[] = array(
@ -399,23 +399,7 @@ 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);
@ -560,13 +544,11 @@ 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);
@ -577,7 +559,6 @@ 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);
@ -588,31 +569,7 @@ 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);