From a46382295b3cac22a3da3b8a2cb3b577b3097053 Mon Sep 17 00:00:00 2001 From: David Staniec Date: Wed, 19 Feb 2025 08:03:51 +0800 Subject: [PATCH] Initial commit --- .../Octopus.Manager.Tentacle.csproj | 12 +++++------ .../Commands/ExtractCommand.cs | 3 ++- .../Octopus.Tentacle/Octopus.Tentacle.csproj | 10 ++++------ .../Packages/IPackageInstaller.cs | 6 ++++-- .../Packages/NuGetPackageInstaller.cs | 20 +++++++++++-------- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/source/Octopus.Manager.Tentacle/Octopus.Manager.Tentacle.csproj b/source/Octopus.Manager.Tentacle/Octopus.Manager.Tentacle.csproj index d8bd4002b..40ab5438a 100644 --- a/source/Octopus.Manager.Tentacle/Octopus.Manager.Tentacle.csproj +++ b/source/Octopus.Manager.Tentacle/Octopus.Manager.Tentacle.csproj @@ -126,12 +126,12 @@ - - - - - - + + + + + + diff --git a/source/Octopus.Tentacle/Commands/ExtractCommand.cs b/source/Octopus.Tentacle/Commands/ExtractCommand.cs index a2239984f..64de94af4 100644 --- a/source/Octopus.Tentacle/Commands/ExtractCommand.cs +++ b/source/Octopus.Tentacle/Commands/ExtractCommand.cs @@ -56,7 +56,8 @@ protected override void Start() { try { - var extracted = packageInstaller.Value.Install(packageFile, destinationDirectory, log, true); + var extractedTask = packageInstaller.Value.Install(packageFile, destinationDirectory, log, true, CancellationToken.None); + var extracted = extractedTask.GetAwaiter().GetResult(); log.Info($"{extracted:n0} files extracted"); return; } diff --git a/source/Octopus.Tentacle/Octopus.Tentacle.csproj b/source/Octopus.Tentacle/Octopus.Tentacle.csproj index 6247dc364..8b637e37a 100644 --- a/source/Octopus.Tentacle/Octopus.Tentacle.csproj +++ b/source/Octopus.Tentacle/Octopus.Tentacle.csproj @@ -57,12 +57,10 @@ - - - - - - + + + + diff --git a/source/Octopus.Tentacle/Packages/IPackageInstaller.cs b/source/Octopus.Tentacle/Packages/IPackageInstaller.cs index e715de6f2..6a0c78826 100644 --- a/source/Octopus.Tentacle/Packages/IPackageInstaller.cs +++ b/source/Octopus.Tentacle/Packages/IPackageInstaller.cs @@ -1,12 +1,14 @@ using System; using System.IO; +using System.Threading; +using System.Threading.Tasks; using Octopus.Diagnostics; namespace Octopus.Tentacle.Packages { public interface IPackageInstaller { - int Install(string packageFile, string directory, ILog log, bool suppressNestedScriptWarning); - int Install(Stream packageStream, string directory, ILog log, bool suppressNestedScriptWarning); + Task Install(string packageFile, string directory, ILog log, bool suppressNestedScriptWarning, CancellationToken cancellationToken); + Task Install(Stream packageStream, string directory, ILog log, bool suppressNestedScriptWarning, CancellationToken cancellationToken); } } \ No newline at end of file diff --git a/source/Octopus.Tentacle/Packages/NuGetPackageInstaller.cs b/source/Octopus.Tentacle/Packages/NuGetPackageInstaller.cs index 2dee382b1..5793aba48 100644 --- a/source/Octopus.Tentacle/Packages/NuGetPackageInstaller.cs +++ b/source/Octopus.Tentacle/Packages/NuGetPackageInstaller.cs @@ -2,11 +2,14 @@ using System.IO; using System.Linq; using System.Threading; +using System.Threading.Tasks; using NuGet.Common; -using NuGet.Packaging; -using NuGet.Packaging.Core; +using NuGet.Configuration; using Octopus.Diagnostics; using Octopus.Tentacle.Util; +using NuGet.Packaging; +using NuGet.Packaging.Core; +using NuGet.Packaging.Signing; namespace Octopus.Tentacle.Packages { @@ -19,20 +22,21 @@ public NuGetPackageInstaller(IOctopusFileSystem fileSystem) this.fileSystem = fileSystem; } - public int Install(string packageFile, string directory, ILog log, bool suppressNestedScriptWarning) + public async Task Install(string packageFile, string directory, ILog log, bool suppressNestedScriptWarning, CancellationToken cancellationToken) { using (var packageStream = fileSystem.OpenFile(packageFile, FileMode.Open, FileAccess.Read)) { - return Install(packageStream, directory, log, suppressNestedScriptWarning); + return await Install(packageStream, directory, log, suppressNestedScriptWarning, cancellationToken); } } - public int Install(Stream packageStream, string directory, ILog log, bool suppressNestedScriptWarning) + public async Task Install(Stream packageStream, string directory, ILog log, bool suppressNestedScriptWarning, CancellationToken cancellationToken) { - var extracted = PackageExtractor.ExtractPackage(packageStream, + var extracted = await PackageExtractor.ExtractPackageAsync( + string.Empty, + packageStream, new SuppliedDirectoryPackagePathResolver(directory), - new PackageExtractionContext(NullLogger.Instance) { PackageSaveMode = PackageSaveMode.Files, XmlDocFileSaveMode = XmlDocFileSaveMode.None, CopySatelliteFiles = false }, - CancellationToken.None); + new PackageExtractionContext(PackageSaveMode.Files, XmlDocFileSaveMode.None, ClientPolicyContext.GetClientPolicy(new NullSettings(), new NullLogger()), new NullLogger()) { CopySatelliteFiles = false }, cancellationToken); return extracted.Count(); }