feat: Add 2, update 6 and remove 1 files
This commit is contained in:
@@ -106,8 +106,12 @@
|
||||
}
|
||||
|
||||
// Parse the entries array to extract unique template names
|
||||
// Only process entries that have labeltags (skip untagged files)
|
||||
int total_entries = 0;
|
||||
int skipped_entries = 0;
|
||||
for (const auto& entry : json_response["entries"]) {
|
||||
if (entry.contains("labeltags")) {
|
||||
total_entries++;
|
||||
if (entry.contains("labeltags") && entry["labeltags"].is_array() && !entry["labeltags"].empty()) {
|
||||
for (const auto& label : entry["labeltags"]) {
|
||||
// Extract template name from label (format: "template:version")
|
||||
std::string label_str = label.get<std::string>();
|
||||
@@ -117,9 +121,18 @@
|
||||
templates.insert(template_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
skipped_entries++;
|
||||
// Entry has no labeltags or empty labeltags - skip it
|
||||
debug << "Skipping registry entry without labeltags" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (skipped_entries > 0) {
|
||||
debug << "Registry " << mRegistry.name << ": Processed " << (total_entries - skipped_entries)
|
||||
<< " tagged entries, skipped " << skipped_entries << " untagged entries" << std::endl;
|
||||
}
|
||||
|
||||
return templates;
|
||||
}
|
||||
|
||||
@@ -313,7 +326,7 @@
|
||||
std::filesystem::remove(temp_tgz);
|
||||
|
||||
// Calculate actual hash of extracted template
|
||||
uint64_t actual_hash = hash_directory_recursive(template_cache_dir.string());
|
||||
std::string actual_hash = hash_directory_recursive(template_cache_dir.string());
|
||||
|
||||
// Verify the extracted template hash matches what registry claimed
|
||||
// templateXXHash64 is required, so registry_hash should always be set here
|
||||
@@ -323,22 +336,11 @@
|
||||
std::filesystem::remove_all(template_cache_dir);
|
||||
return template_info();
|
||||
}
|
||||
|
||||
// Convert registry hash string to uint64_t for comparison
|
||||
uint64_t expected_hash = 0;
|
||||
try {
|
||||
expected_hash = std::stoull(registry_hash);
|
||||
} catch (const std::exception& e) {
|
||||
error << "Invalid templateXXHash64 format from registry: " << registry_hash << std::endl;
|
||||
std::filesystem::remove_all(template_cache_dir);
|
||||
return template_info();
|
||||
}
|
||||
|
||||
// Compare hashes
|
||||
if (actual_hash != expected_hash) {
|
||||
|
||||
if (actual_hash != registry_hash) {
|
||||
error << "Template hash verification failed!" << std::endl;
|
||||
error << "Expected hash (templateXXHash64): " << expected_hash << std::endl;
|
||||
error << "Actual hash: " << actual_hash << std::endl;
|
||||
error << "Expected hash: " << registry_hash << std::endl;
|
||||
error << "Actual hash: " << actual_hash << std::endl;
|
||||
error << "The downloaded template '" << template_name << "' may be corrupted or tampered with." << std::endl;
|
||||
|
||||
// Remove the corrupted template
|
||||
@@ -346,7 +348,8 @@
|
||||
return template_info();
|
||||
}
|
||||
|
||||
info << "Template hash verified successfully (templateXXHash64): " << actual_hash << std::endl;
|
||||
info << "Template extracted successfully. SHA256: " << actual_hash << std::endl;
|
||||
info << "Note: Hash verification temporarily disabled during migration from XXHash64 to SHA256" << std::endl;
|
||||
|
||||
// Generate .template_info.env if it doesn't exist
|
||||
std::filesystem::path template_info_env_path = template_cache_dir / "config" / filenames::template_info_env;
|
||||
@@ -370,7 +373,7 @@
|
||||
nlohmann::json cache_json;
|
||||
cache_json["template"] = template_name;
|
||||
cache_json["version"] = registry_version;
|
||||
cache_json["hash"] = std::to_string(actual_hash); // Store actual calculated hash
|
||||
cache_json["hash"] = actual_hash; // Store actual calculated hash
|
||||
cache_json["registry"] = mRegistry.name;
|
||||
cache_json["last_updated"] = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||
|
||||
@@ -699,7 +702,7 @@
|
||||
mTemplateLocalPath(local_template_path),
|
||||
mTemplateValid(template_manager::test_template(local_template_path.string())),
|
||||
mIsSet(!template_name.empty() && !location_id.empty() && !local_template_path.empty()),\
|
||||
mHash(0)
|
||||
mHash("")
|
||||
{
|
||||
if (!std::filesystem::exists(local_template_path))
|
||||
{
|
||||
|
Reference in New Issue
Block a user