Skip to content

Commit

Permalink
Merge pull request #336 from Squirrel/bring-back-bsdiff
Browse files Browse the repository at this point in the history
Bring back bsdiff as a fallback
  • Loading branch information
anaisbetts committed May 9, 2015
2 parents a799b12 + fba70f4 commit 281bf59
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/Squirrel/ContentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static void Merge(XmlDocument doc)
{
var elements = new [] {
Tuple.Create("Default", "diff", "application/octet" ),
Tuple.Create("Default", "bsdiff", "application/octet" ),
Tuple.Create("Default", "exe", "application/octet" ),
Tuple.Create("Default", "dll", "application/octet" ),
Tuple.Create("Default", "shasum", "text/plain" ),
Expand Down
36 changes: 30 additions & 6 deletions src/Squirrel/DeltaPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Splat;
using DeltaCompressionDotNet.MsDelta;
using System.ComponentModel;
using Squirrel.Bsdiff;

namespace Squirrel
{
Expand Down Expand Up @@ -176,9 +177,25 @@ void createDeltaForSingleFile(FileInfo targetFile, DirectoryInfo workingDirector
var msDelta = new MsDeltaCompression();
try {
msDelta.CreateDelta(baseFileListing[relativePath], targetFile.FullName, targetFile.FullName + ".diff");
} catch (Win32Exception ex) {
this.Log().Warn("We couldn't create a delta for {0}, writing full file", targetFile.Name);
return;
} catch (Win32Exception) {
this.Log().Warn("We couldn't create a delta for {0}, attempting to create bsdiff", targetFile.Name);

var of = default(FileStream);
try {
of = File.Create(targetFile.FullName + ".bsdiff");
BinaryPatchUtility.Create(oldData, newData, of);

// NB: Create a dummy corrupt .diff file so that older
// versions which don't understand bsdiff will fail out
// until they get upgraded, instead of seeing the missing
// file and just removing it.
File.WriteAllText(targetFile.FullName + ".diff", "1");
} catch (Exception ex) {
this.Log().WarnException(String.Format("We really couldn't create a delta for {0}", targetFile.Name), ex);
return;
} finally {
if (of != null) of.Dispose();
}
}

var rl = ReleaseEntry.GenerateFromFile(new MemoryStream(newData), targetFile.Name + ".shasum");
Expand All @@ -202,13 +219,20 @@ void applyDiffToFile(string deltaPath, string relativeFilePath, string workingDi
return;
}

if (relativeFilePath.EndsWith(".diff", StringComparison.InvariantCultureIgnoreCase)) {
this.Log().Info("Applying Diff to {0}", relativeFilePath);
if (relativeFilePath.EndsWith(".bsdiff", StringComparison.InvariantCultureIgnoreCase)) {
using (var of = File.OpenWrite(tempTargetFile))
using (var inf = File.OpenRead(finalTarget)) {
this.Log().Info("Applying BSDiff to {0}", relativeFilePath);
BinaryPatchUtility.Apply(inf, () => File.OpenRead(inputFile), of);
}

verifyPatchedFile(relativeFilePath, inputFile, tempTargetFile);
} else if (relativeFilePath.EndsWith(".diff", StringComparison.InvariantCultureIgnoreCase)) {
this.Log().Info("Applying MSDiff to {0}", relativeFilePath);
var msDelta = new MsDeltaCompression();
msDelta.ApplyDelta(inputFile, finalTarget, tempTargetFile);

verifyPatchedFile(relativeFilePath, inputFile, tempTargetFile);

} else {
using (var of = File.OpenWrite(tempTargetFile))
using (var inf = File.OpenRead(inputFile)) {
Expand Down
2 changes: 0 additions & 2 deletions src/Squirrel/ReleasePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,13 @@ public string CreateReleasePackage(string outputFile, string packagesRootDir = n
// ever expect one entry here (crash hard otherwise)
var frameworks = package.GetSupportedFrameworks();
if (frameworks.Count() > 1) {

var platforms = frameworks
.Aggregate(new StringBuilder(), (sb, f) => sb.Append(f.ToString() + "; "));

throw new InvalidOperationException(String.Format(
"The input package file {0} targets multiple platforms - {1} - and cannot be transformed into a release package.", InputPackageFile, platforms));

} else if (!frameworks.Any()) {

throw new InvalidOperationException(String.Format(
"The input package file {0} targets no platform and cannot be transformed into a release package.", InputPackageFile));
}
Expand Down
1 change: 1 addition & 0 deletions src/Squirrel/Squirrel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<Compile Include="..\SolutionAssemblyInfo.cs">
<Link>Properties\SolutionAssemblyInfo.cs</Link>
</Compile>
<Compile Include="BinaryPatchUtility.cs" />
<Compile Include="ContentType.cs" />
<Compile Include="DeltaPackage.cs" />
<Compile Include="EnumerableExtensions.cs" />
Expand Down

0 comments on commit 281bf59

Please sign in to comment.