Skip to content

Commit 8c8bc89

Browse files
authored
Updates for Update-PSResource (#534)
* Changes to UpdatePSResource command * Add stop processing to UpdatePSResource. Removed multiple instantiations of helper objects. * Reverting to original source * Create InstallHelper object only once.
1 parent 4fdef60 commit 8c8bc89

File tree

8 files changed

+3655
-1345
lines changed

8 files changed

+3655
-1345
lines changed

Notice.txt

Lines changed: 2167 additions & 0 deletions
Large diffs are not rendered by default.

doBuild.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ function DoBuild
4141
Copy-Item -Path "./LICENSE" -Dest "$BuildOutPath"
4242

4343
# Copy notice
44-
# Write-Verbose -Verbose -Message "Copying ThirdPartyNotices.txt to '$BuildOutPath'"
45-
# Copy-Item -Path "./ThirdPartyNotices.txt" -Dest "$BuildOutPath"
44+
Write-Verbose -Verbose -Message "Copying ThirdPartyNotices.txt to '$BuildOutPath'"
45+
Copy-Item -Path "./Notice.txt" -Dest "$BuildOutPath"
4646

4747
#
4848
# Copy DSC resources

src/code/FindPSResource.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using Microsoft.PowerShell.PowerShellGet.UtilClasses;
45
using System;
56
using System.Collections.Generic;
6-
using Dbg = System.Diagnostics.Debug;
77
using System.Linq;
88
using System.Management.Automation;
99
using System.Threading;
10-
using Microsoft.PowerShell.PowerShellGet.UtilClasses;
10+
11+
using Dbg = System.Diagnostics.Debug;
1112

1213
namespace Microsoft.PowerShell.PowerShellGet.Cmdlets
1314
{
@@ -29,8 +30,8 @@ public sealed class FindPSResource : PSCmdlet
2930
private const string ResourceNameParameterSet = "ResourceNameParameterSet";
3031
private const string CommandNameParameterSet = "CommandNameParameterSet";
3132
private const string DscResourceNameParameterSet = "DscResourceNameParameterSet";
32-
private CancellationTokenSource _source;
33-
private CancellationToken _cancellationToken;
33+
private CancellationTokenSource _cancellationTokenSource;
34+
private FindHelper _findHelper;
3435

3536
#endregion
3637

@@ -132,17 +133,25 @@ public sealed class FindPSResource : PSCmdlet
132133

133134
protected override void BeginProcessing()
134135
{
135-
_source = new CancellationTokenSource();
136-
_cancellationToken = _source.Token;
136+
_cancellationTokenSource = new CancellationTokenSource();
137+
_findHelper = new FindHelper(
138+
cancellationToken: _cancellationTokenSource.Token,
139+
cmdletPassedIn: this);
137140

138-
// Create a respository story (the PSResourceRepository.xml file) if it does not already exist
141+
// Create a repository story (the PSResourceRepository.xml file) if it does not already exist
139142
// This is to create a better experience for those who have just installed v3 and want to get up and running quickly
140143
RepositorySettings.CheckRepositoryStore();
141144
}
142145

143146
protected override void StopProcessing()
144147
{
145-
_source.Cancel();
148+
_cancellationTokenSource?.Cancel();
149+
}
150+
151+
protected override void EndProcessing()
152+
{
153+
_cancellationTokenSource.Dispose();
154+
_cancellationTokenSource = null;
146155
}
147156

148157
protected override void ProcessRecord()
@@ -207,10 +216,9 @@ private void ProcessResourceNameParameterSet()
207216
return;
208217
}
209218

210-
FindHelper findHelper = new FindHelper(_cancellationToken, this);
211219
List<PSResourceInfo> foundPackages = new List<PSResourceInfo>();
212220

213-
foreach (PSResourceInfo package in findHelper.FindByResourceName(
221+
foreach (PSResourceInfo package in _findHelper.FindByResourceName(
214222
Name,
215223
Type,
216224
Version,
@@ -283,10 +291,9 @@ private void ProcessCommandOrDscParameterSet(bool isSearchingForCommands)
283291
moduleNamesToSearch = new string[] {"*"};
284292
}
285293

286-
FindHelper findHelper = new FindHelper(_cancellationToken, this);
287294
List<PSResourceInfo> foundPackages = new List<PSResourceInfo>();
288295

289-
foreach (PSResourceInfo package in findHelper.FindByResourceName(
296+
foreach (PSResourceInfo package in _findHelper.FindByResourceName(
290297
name: moduleNamesToSearch,
291298
// provide type so Scripts endpoint for PSGallery won't be searched
292299
type: isSearchingForCommands? ResourceType.Command : ResourceType.DscResource,

0 commit comments

Comments
 (0)