Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Add more retry resiliency to CreatePackageBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Jul 3, 2022
1 parent 26f55e9 commit 1294211
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Squirrel.CommandLine/Windows/SetupBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static bool IsBundle(string setupPath, out long bundleOffset, out long bu

long offset = 0;
long length = 0;

void FindBundleHeader()
{
using (var memoryMappedFile = MemoryMappedFile.CreateFromFile(setupPath, FileMode.Open, null, 0, MemoryMappedFileAccess.Read))
Expand All @@ -46,11 +47,17 @@ void FindBundleHeader()
public static long CreatePackageBundle(string setupPath, string packagePath)
{
long bundleOffset, bundleLength;
using (var pkgStream = File.OpenRead(packagePath))
using (var setupStream = File.Open(setupPath, FileMode.Append, FileAccess.Write)) {
Stream pkgStream = null, setupStream = null;

try {
pkgStream = Utility.Retry(() => File.OpenRead(packagePath), retries: 10);
setupStream = Utility.Retry(() => File.Open(setupPath, FileMode.Append, FileAccess.Write), retries: 10);
bundleOffset = setupStream.Position;
bundleLength = pkgStream.Length;
pkgStream.CopyTo(setupStream);
} finally {
if (pkgStream != null) pkgStream.Dispose();
if (setupStream != null) setupStream.Dispose();
}

byte[] placeholder = {
Expand Down Expand Up @@ -83,4 +90,4 @@ public static long CreatePackageBundle(string setupPath, string packagePath)
return bundleOffset;
}
}
}
}

0 comments on commit 1294211

Please sign in to comment.