in src/managed/DiffGen/DiffGeneration/Utility/ToolBasedDeltaBuilder.cs [46:151]
public override bool Call(
ILogger logger,
ItemDefinition sourceItem,
string sourceFile,
ItemDefinition targetItem,
string targetFile,
string baseDeltaFile,
out ItemDefinition deltaItem,
out string deltaFile,
out Recipe recipe)
{
deltaFile = GetDecoratedPath(baseDeltaFile);
var tempDelta = TempDeltaPath(deltaFile);
var badDiff = BadDeltaPath(deltaFile);
if (File.Exists(badDiff))
{
logger.LogDebug($"{GetType().Name}: Skipping file, detected bad delta: {badDiff}");
recipe = null;
deltaItem = null;
return false;
}
if (File.Exists(deltaFile))
{
deltaItem = ItemDefinition.FromFile(deltaFile);
if (deltaItem.Length == 0)
{
File.Delete(deltaFile);
}
else if (deltaItem.Length >= targetItem.Length)
{
Worker.CreateCookie(badDiff);
logger.LogDebug("Skipping delta - length of {0} >= the target length of {1}", deltaItem.Length, targetItem.Length);
recipe = null;
deltaItem = null;
return false;
}
else
{
recipe = CreateDecompressionRecipe(targetItem, deltaItem, sourceItem);
return true;
}
}
EnsureParentPath(deltaFile);
int timeout = TimeoutValueGenerator.GetTimeoutValue(sourceFile, targetFile);
using (Process process = new())
{
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = ProcessHelper.GetPathInRunningDirectory(BinaryPath);
process.StartInfo.CreateNoWindow = true;
process.StartInfo.Arguments = FormatArgs(sourceFile, targetFile, tempDelta);
process.StartAndReport();
process.WaitForExit(timeout, CancellationToken);
if (process.HasExited && process.ExitCode == 0)
{
if (!File.Exists(tempDelta))
{
throw new Exception($"{GetType().Name}: didn't create file. Diff: {tempDelta}. BinaryPath: {process.StartInfo.FileName}, Args: {process.StartInfo.Arguments}");
}
MoveFileWithRetries(tempDelta, deltaFile);
deltaItem = ItemDefinition.FromFile(deltaFile);
if (deltaItem.Length >= targetItem.Length)
{
Worker.CreateCookie(badDiff);
logger.LogDebug("Skipping delta - length of {0} >= the target length of {1}", deltaItem.Length, targetItem.Length);
recipe = null;
deltaItem = null;
return false;
}
recipe = CreateDecompressionRecipe(targetItem, deltaItem, sourceItem);
return true;
}
logger.LogDebug($"{GetType().Name}: Failed. Creating bad diff: {badDiff}");
Worker.CreateCookie(badDiff);
if (!process.HasExited)
{
logger.LogDebug($"{GetType().Name}: Killing diff process. Timeout of {timeout / 1000} seconds was exceeded.");
process.Kill(true);
}
if (File.Exists(tempDelta))
{
File.Delete(tempDelta);
}
recipe = null;
deltaItem = null;
return false;
}
}