using StellaOps.AirGap.Bundle.Models; namespace StellaOps.AirGap.Bundle.Services; public sealed partial class SnapshotBundleWriter { private static async Task WriteRuleBundlesAsync( SnapshotBundleRequest request, string tempDir, List entries, KnowledgeSnapshotManifest manifest, CancellationToken cancellationToken) { if (request.RuleBundles is not { Count: > 0 }) { return; } var rulesDir = Path.Combine(tempDir, "rules"); Directory.CreateDirectory(rulesDir); foreach (var ruleBundle in request.RuleBundles) { var bundleDir = Path.Combine(rulesDir, ruleBundle.BundleId); Directory.CreateDirectory(bundleDir); var bundleFiles = new List(); var bundleRelativePath = $"rules/{ruleBundle.BundleId}"; foreach (var file in ruleBundle.Files) { var filePath = Path.Combine(bundleDir, file.Name); await File.WriteAllBytesAsync(filePath, file.Content, cancellationToken).ConfigureAwait(false); var relativePath = $"{bundleRelativePath}/{file.Name}"; var digest = AddEntry(entries, relativePath, file.Content); bundleFiles.Add(new RuleBundleFile { Name = file.Name, Digest = digest, SizeBytes = file.Content.Length }); } manifest.RuleBundles.Add(new RuleBundleSnapshotEntry { BundleId = ruleBundle.BundleId, BundleType = ruleBundle.BundleType, Version = ruleBundle.Version, RelativePath = bundleRelativePath, Files = bundleFiles, RuleCount = ruleBundle.RuleCount, SignerKeyId = ruleBundle.SignerKeyId, SignedAt = ruleBundle.SignedAt, VerifiedAt = ruleBundle.VerifiedAt }); } } }