From 59efd51796c40cea0dce1826e767254cad1394c0 Mon Sep 17 00:00:00 2001 From: TheCakeIsNaOH Date: Sat, 22 May 2021 15:55:48 -0500 Subject: [PATCH] (#2076) Pack always truncate stream Mono does not truncate streams in System.IO.Packaging.Package.Open when using FileMode.Create, while .Net does. mono/mono#21055 This always truncates the stream at the start. --- src/chocolatey/infrastructure.app/nuget/NugetPack.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/chocolatey/infrastructure.app/nuget/NugetPack.cs b/src/chocolatey/infrastructure.app/nuget/NugetPack.cs index 7b37a72d2b..df01400710 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetPack.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetPack.cs @@ -36,6 +36,11 @@ public static IPackage BuildPackage(PackageBuilder builder, IFileSystem fileSyst { using (Stream stream = fileSystem.create_file(outputPath)) { + // Truncate if needed, as Mono fails to truncate + if (stream.Length > 0) + { + stream.SetLength(0); + } builder.Save(stream); } }