@@ -60,7 +60,7 @@ internal class InstallHelper
60
60
61
61
public InstallHelper ( PSCmdlet cmdletPassedIn , NetworkCredential networkCredential )
62
62
{
63
- CancellationTokenSource source = new CancellationTokenSource ( ) ;
63
+ CancellationTokenSource source = new ( ) ;
64
64
_cancellationToken = source . Token ;
65
65
_cmdletPassedIn = cmdletPassedIn ;
66
66
_networkCredential = networkCredential ;
@@ -183,7 +183,7 @@ private List<PSResourceInfo> ProcessRepositories(
183
183
ScopeType scope )
184
184
{
185
185
_cmdletPassedIn . WriteDebug ( "In InstallHelper::ProcessRepositories()" ) ;
186
- List < PSResourceInfo > allPkgsInstalled = new List < PSResourceInfo > ( ) ;
186
+ List < PSResourceInfo > allPkgsInstalled = new ( ) ;
187
187
if ( repository != null && repository . Length != 0 )
188
188
{
189
189
// Write error and disregard repository entries containing wildcards.
@@ -262,7 +262,7 @@ private List<PSResourceInfo> ProcessRepositories(
262
262
var noToAll = false ;
263
263
264
264
var findHelper = new FindHelper ( _cancellationToken , _cmdletPassedIn , _networkCredential ) ;
265
- List < string > repositoryNamesToSearch = new List < string > ( ) ;
265
+ List < string > repositoryNamesToSearch = new ( ) ;
266
266
bool sourceTrusted = false ;
267
267
268
268
// Loop through all the repositories provided (in priority order) until there no more packages to install.
@@ -330,7 +330,7 @@ private List<PSResourceInfo> ProcessRepositories(
330
330
allPkgsInstalled . AddRange ( installedPkgs ) ;
331
331
}
332
332
333
- if ( _pkgNamesToInstall . Count > 0 )
333
+ if ( ! _cmdletPassedIn . MyInvocation . BoundParameters . ContainsKey ( "WhatIf" ) && _pkgNamesToInstall . Count > 0 )
334
334
{
335
335
string repositoryWording = repositoryNamesToSearch . Count > 1 ? "registered repositories" : "repository" ;
336
336
_cmdletPassedIn . WriteError ( new ErrorRecord (
@@ -547,7 +547,7 @@ private List<PSResourceInfo> InstallPackages(
547
547
FindHelper findHelper )
548
548
{
549
549
_cmdletPassedIn . WriteDebug ( "In InstallHelper::InstallPackages()" ) ;
550
- List < PSResourceInfo > pkgsSuccessfullyInstalled = new List < PSResourceInfo > ( ) ;
550
+ List < PSResourceInfo > pkgsSuccessfullyInstalled = new ( ) ;
551
551
552
552
// Install parent package to the temp directory,
553
553
// Get the dependencies from the installed package,
@@ -658,7 +658,7 @@ private List<PSResourceInfo> InstallPackages(
658
658
}
659
659
660
660
// If -WhatIf is passed in, early out.
661
- if ( ! _cmdletPassedIn . ShouldProcess ( "Exit ShouldProcess ") )
661
+ if ( _cmdletPassedIn . MyInvocation . BoundParameters . ContainsKey ( "WhatIf ") )
662
662
{
663
663
return pkgsSuccessfullyInstalled ;
664
664
}
@@ -1203,7 +1203,7 @@ private bool TryExtractToDirectory(string zipPath, string extractPath, out Error
1203
1203
{
1204
1204
using ( ZipArchive archive = ZipFile . OpenRead ( zipPath ) )
1205
1205
{
1206
- foreach ( ZipArchiveEntry entry in archive . Entries )
1206
+ foreach ( ZipArchiveEntry entry in archive . Entries . Where ( entry => entry . CompressedLength > 0 ) )
1207
1207
{
1208
1208
// If a file has one or more parent directories.
1209
1209
if ( entry . FullName . Contains ( Path . DirectorySeparatorChar ) || entry . FullName . Contains ( Path . AltDirectorySeparatorChar ) )
@@ -1328,17 +1328,17 @@ private bool CallAcceptLicense(PSResourceInfo p, string moduleManifest, string t
1328
1328
1329
1329
if ( File . Exists ( moduleManifest ) )
1330
1330
{
1331
- using ( StreamReader sr = new StreamReader ( moduleManifest ) )
1331
+ using ( StreamReader sr = new ( moduleManifest ) )
1332
1332
{
1333
1333
var text = sr . ReadToEnd ( ) ;
1334
1334
1335
1335
var pattern = "RequireLicenseAcceptance\\ s*=\\ s*\\ $true" ;
1336
1336
var patternToSkip1 = "#\\ s*RequireLicenseAcceptance\\ s*=\\ s*\\ $true" ;
1337
1337
var patternToSkip2 = "\\ *\\ s*RequireLicenseAcceptance\\ s*=\\ s*\\ $true" ;
1338
1338
1339
- Regex rgx = new Regex ( pattern ) ;
1340
- Regex rgxComment1 = new Regex ( patternToSkip1 ) ;
1341
- Regex rgxComment2 = new Regex ( patternToSkip2 ) ;
1339
+ Regex rgx = new ( pattern ) ;
1340
+ Regex rgxComment1 = new ( patternToSkip1 ) ;
1341
+ Regex rgxComment2 = new ( patternToSkip2 ) ;
1342
1342
if ( rgx . IsMatch ( text ) && ! rgxComment1 . IsMatch ( text ) && ! rgxComment2 . IsMatch ( text ) )
1343
1343
{
1344
1344
requireLicenseAcceptance = true ;
@@ -1409,14 +1409,14 @@ private bool DetectClobber(string pkgName, Hashtable parsedMetadataHashtable, ou
1409
1409
1410
1410
// Get installed modules, then get all possible paths
1411
1411
// selectPrereleaseOnly is false because even if Prerelease is true we want to include both stable and prerelease, would never select prerelease only.
1412
- GetHelper getHelper = new GetHelper ( _cmdletPassedIn ) ;
1412
+ GetHelper getHelper = new ( _cmdletPassedIn ) ;
1413
1413
IEnumerable < PSResourceInfo > pkgsAlreadyInstalled = getHelper . GetPackagesFromPath (
1414
1414
name : new string [ ] { "*" } ,
1415
1415
versionRange : VersionRange . All ,
1416
1416
pathsToSearch : _pathsToSearch ,
1417
1417
selectPrereleaseOnly : false ) ;
1418
1418
1419
- List < string > listOfCmdlets = new List < string > ( ) ;
1419
+ List < string > listOfCmdlets = new ( ) ;
1420
1420
if ( parsedMetadataHashtable . ContainsKey ( "CmdletsToExport" ) )
1421
1421
{
1422
1422
if ( parsedMetadataHashtable [ "CmdletsToExport" ] is object [ ] cmdletsToExport )
@@ -1430,8 +1430,8 @@ private bool DetectClobber(string pkgName, Hashtable parsedMetadataHashtable, ou
1430
1430
1431
1431
foreach ( var pkg in pkgsAlreadyInstalled )
1432
1432
{
1433
- List < string > duplicateCmdlets = new List < string > ( ) ;
1434
- List < string > duplicateCmds = new List < string > ( ) ;
1433
+ List < string > duplicateCmdlets = new ( ) ;
1434
+ List < string > duplicateCmds = new ( ) ;
1435
1435
// See if any of the cmdlets or commands in the pkg we're trying to install exist within a package that's already installed
1436
1436
if ( pkg . Includes . Cmdlet != null && pkg . Includes . Cmdlet . Length != 0 )
1437
1437
{
0 commit comments