@@ -15,7 +15,7 @@ namespace NuGet.Services.Validation.Orchestrator
1515 public class ValidationOutcomeProcessor : IValidationOutcomeProcessor
1616 {
1717 private readonly ICorePackageService _galleryPackageService ;
18- private readonly ICorePackageFileService _packageFileService ;
18+ private readonly IValidationPackageFileService _packageFileService ;
1919 private readonly IPackageValidationEnqueuer _validationEnqueuer ;
2020 private readonly ValidationConfiguration _validationConfiguration ;
2121 private readonly IMessageService _messageService ;
@@ -24,7 +24,7 @@ public class ValidationOutcomeProcessor : IValidationOutcomeProcessor
2424
2525 public ValidationOutcomeProcessor (
2626 ICorePackageService galleryPackageService ,
27- ICorePackageFileService packageFileService ,
27+ IValidationPackageFileService packageFileService ,
2828 IPackageValidationEnqueuer validationEnqueuer ,
2929 IOptionsSnapshot < ValidationConfiguration > validationConfigurationAccessor ,
3030 IMessageService messageService ,
@@ -106,6 +106,8 @@ ValidationConfigurationItem GetValidationConfigurationItem(string validationName
106106 validationSet . ValidationTrackingId ) ;
107107 }
108108
109+ await _packageFileService . DeletePackageForValidationSetAsync ( validationSet ) ;
110+
109111 TrackTotalValidationDuration ( validationSet , isSuccess : false ) ;
110112 }
111113 else if ( AllValidationsSucceeded ( validationSet , GetValidationConfigurationItem ) )
@@ -114,6 +116,7 @@ ValidationConfigurationItem GetValidationConfigurationItem(string validationName
114116 package . PackageRegistration . Id ,
115117 package . NormalizedVersion ,
116118 validationSet . ValidationTrackingId ) ;
119+
117120 if ( package . PackageStatusKey != PackageStatus . Available )
118121 {
119122 await MoveFileToPublicStorageAndMarkPackageAsAvailable ( validationSet , package ) ;
@@ -139,6 +142,9 @@ ValidationConfigurationItem GetValidationConfigurationItem(string validationName
139142 TrackMissingNupkgForAvailablePackage ( validationSet ) ;
140143 }
141144 }
145+
146+ await _packageFileService . DeletePackageForValidationSetAsync ( validationSet ) ;
147+
142148 _logger . LogInformation ( "Done processing {PackageId} {PackageVersion} {ValidationSetId}" ,
143149 package . PackageRegistration . Id ,
144150 package . NormalizedVersion ,
@@ -176,23 +182,27 @@ private async Task MoveFileToPublicStorageAndMarkPackageAsAvailable(PackageValid
176182 package . PackageRegistration . Id ,
177183 package . NormalizedVersion ,
178184 validationSet . ValidationTrackingId ) ;
179- var packageStream = await _packageFileService . DownloadValidationPackageFileAsync ( package ) ;
180185
181- try
186+ if ( await _packageFileService . DoesValidationSetPackageExistAsync ( validationSet ) )
182187 {
183- await _packageFileService . SavePackageFileAsync ( package , packageStream ) ;
188+ await CopyAsync (
189+ validationSet ,
190+ package ,
191+ x => _packageFileService . CopyValidationSetPackageToPackageFileAsync ( x ) ) ;
184192 }
185- catch ( InvalidOperationException )
193+ else
186194 {
187- // The package already exists in the packages container. This can happen if the DB commit below fails
188- // and this flow is retried. We assume that the package content has not changed. Today there is no way
189- // for the content to change. Hard deletes (the one way a package ID and version can get different
190- // content) delete from both the packages and validating container so this can't be a mismatch.
191195 _logger . LogInformation (
192- "Package already exists in packages container for {PackageId} {PackageVersion}, validation set {ValidationSetId}" ,
196+ "The package specific to the validation set does not exist. Falling back to the validation " +
197+ "container for package {PackageId} {PackageVersion}, validation set {ValidationSetId}" ,
193198 package . PackageRegistration . Id ,
194199 package . NormalizedVersion ,
195200 validationSet . ValidationTrackingId ) ;
201+
202+ await CopyAsync (
203+ validationSet ,
204+ package ,
205+ x => _packageFileService . CopyValidationPackageToPackageFileAsync ( x . PackageId , x . PackageNormalizedVersion ) ) ;
196206 }
197207
198208 _logger . LogInformation ( "Marking package {PackageId} {PackageVersion}, validation set {ValidationSetId} as {PackageStatus} in DB" ,
@@ -229,6 +239,26 @@ private async Task MoveFileToPublicStorageAndMarkPackageAsAvailable(PackageValid
229239 await _packageFileService . DeleteValidationPackageFileAsync ( package . PackageRegistration . Id , package . Version ) ;
230240 }
231241
242+ private async Task CopyAsync ( PackageValidationSet validationSet , Package package , Func < PackageValidationSet , Task > copyAsync )
243+ {
244+ try
245+ {
246+ await copyAsync ( validationSet ) ;
247+ }
248+ catch ( InvalidOperationException )
249+ {
250+ // The package already exists in the packages container. This can happen if the DB commit below fails
251+ // and this flow is retried. We assume that the package content has not changed. Today there is no way
252+ // for the content to change. Hard deletes (the one way a package ID and version can get different
253+ // content) delete from both the packages and validating container so this can't be a mismatch.
254+ _logger . LogInformation (
255+ "Package already exists in packages container for {PackageId} {PackageVersion}, validation set {ValidationSetId}" ,
256+ package . PackageRegistration . Id ,
257+ package . NormalizedVersion ,
258+ validationSet . ValidationTrackingId ) ;
259+ }
260+ }
261+
232262 private bool AllValidationsSucceeded (
233263 PackageValidationSet packageValidationSet ,
234264 Func < string , ValidationConfigurationItem > getValidationConfigurationItem )
0 commit comments