Skip to content

Commit

Permalink
Fix IncrementDownloadCount failing when no statistics entry is in the db
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Mar 12, 2024
1 parent c86a92b commit f7a56c2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/PackageRegistryService/Models/ValidationPackageDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

public static bool ValidatePackageContent(ValidationPackage package, ValidationPackageDb database)
{
var hash = database.Hashes.Single(h => h.PackageName == package.Name && h.PackageMajorVersion == package.MajorVersion && h.PackageMinorVersion == package.MinorVersion && h.PackagePatchVersion == package.PatchVersion);
var hash = database.Hashes.SingleOrDefault(h => h.PackageName == package.Name && h.PackageMajorVersion == package.MajorVersion && h.PackageMinorVersion == package.MinorVersion && h.PackagePatchVersion == package.PatchVersion);

if (hash == null)
{
return false;
}

var packageHash = package.GetPackageContentHash();
return hash.Hash == packageHash;
}

public static void IncrementDownloadCount(ValidationPackage package, ValidationPackageDb database)
{
var result = database.Downloads.Single(d => d.PackageName == package.Name && d.PackageMajorVersion == package.MajorVersion && d.PackageMinorVersion == package.MinorVersion && d.PackagePatchVersion == package.PatchVersion);
var result = database.Downloads.SingleOrDefault(d => d.PackageName == package.Name && d.PackageMajorVersion == package.MajorVersion && d.PackageMinorVersion == package.MinorVersion && d.PackagePatchVersion == package.PatchVersion);

if (result != null)
{
Expand Down

0 comments on commit f7a56c2

Please sign in to comment.