diff --git a/src/Tgstation.Server.Host/Components/Repository/Repository.cs b/src/Tgstation.Server.Host/Components/Repository/Repository.cs
index f076b7de30..f36ede80e6 100644
--- a/src/Tgstation.Server.Host/Components/Repository/Repository.cs
+++ b/src/Tgstation.Server.Host/Components/Repository/Repository.cs
@@ -117,7 +117,23 @@ namespace Tgstation.Server.Host.Components.Repository
/// The of the operation.
/// The stage argument for .
/// A based on .
- static CheckoutProgressHandler CheckoutProgressHandler(JobProgressReporter progressReporter, string stage) => (a, completedSteps, totalSteps) => progressReporter(stage, (int)(((float)completedSteps) / totalSteps * 100));
+ static CheckoutProgressHandler CheckoutProgressHandler(JobProgressReporter progressReporter, string stage) => (a, completedSteps, totalSteps) =>
+ {
+ int? percentage;
+ if (totalSteps > completedSteps || totalSteps == 0)
+ percentage = null;
+ else
+ {
+ var ratio = ((float)completedSteps) / totalSteps;
+ percentage = (int)(ratio * 100);
+ if (percentage < 0)
+ percentage = null;
+ }
+
+ progressReporter(
+ stage,
+ percentage);
+ };
///
/// Generate a from a given and .
@@ -128,8 +144,19 @@ namespace Tgstation.Server.Host.Components.Repository
/// A new based on .
static TransferProgressHandler TransferProgressHandler(JobProgressReporter progressReporter, string stage, CancellationToken cancellationToken) => (transferProgress) =>
{
- var percentage = 100 * (((float)transferProgress.IndexedObjects + transferProgress.ReceivedObjects) / (transferProgress.TotalObjects * 2));
- progressReporter(stage, (int)percentage);
+ float? percentage;
+ var totalObjectsToProcess = transferProgress.TotalObjects * 2;
+ var processedObjects = transferProgress.IndexedObjects + transferProgress.ReceivedObjects;
+ if (totalObjectsToProcess > processedObjects || totalObjectsToProcess == 0)
+ percentage = null;
+ else
+ {
+ percentage = 100 * (((float)processedObjects) / totalObjectsToProcess);
+ if (percentage < 0)
+ percentage = null;
+ }
+
+ progressReporter(stage, (int?)percentage);
return !cancellationToken.IsCancellationRequested;
};