@@ -60,7 +60,7 @@ internal class InstallHelper
6060
6161 public InstallHelper ( PSCmdlet cmdletPassedIn , NetworkCredential networkCredential )
6262 {
63- CancellationTokenSource source = new CancellationTokenSource ( ) ;
63+ CancellationTokenSource source = new ( ) ;
6464 _cancellationToken = source . Token ;
6565 _cmdletPassedIn = cmdletPassedIn ;
6666 _networkCredential = networkCredential ;
@@ -183,7 +183,7 @@ private List<PSResourceInfo> ProcessRepositories(
183183 ScopeType scope )
184184 {
185185 _cmdletPassedIn . WriteDebug ( "In InstallHelper::ProcessRepositories()" ) ;
186- List < PSResourceInfo > allPkgsInstalled = new List < PSResourceInfo > ( ) ;
186+ List < PSResourceInfo > allPkgsInstalled = new ( ) ;
187187 if ( repository != null && repository . Length != 0 )
188188 {
189189 // Write error and disregard repository entries containing wildcards.
@@ -262,7 +262,7 @@ private List<PSResourceInfo> ProcessRepositories(
262262 var noToAll = false ;
263263
264264 var findHelper = new FindHelper ( _cancellationToken , _cmdletPassedIn , _networkCredential ) ;
265- List < string > repositoryNamesToSearch = new List < string > ( ) ;
265+ List < string > repositoryNamesToSearch = new ( ) ;
266266 bool sourceTrusted = false ;
267267
268268 // Loop through all the repositories provided (in priority order) until there no more packages to install.
@@ -330,7 +330,7 @@ private List<PSResourceInfo> ProcessRepositories(
330330 allPkgsInstalled . AddRange ( installedPkgs ) ;
331331 }
332332
333- if ( _pkgNamesToInstall . Count > 0 )
333+ if ( ! _cmdletPassedIn . MyInvocation . BoundParameters . ContainsKey ( "WhatIf" ) && _pkgNamesToInstall . Count > 0 )
334334 {
335335 string repositoryWording = repositoryNamesToSearch . Count > 1 ? "registered repositories" : "repository" ;
336336 _cmdletPassedIn . WriteError ( new ErrorRecord (
@@ -547,7 +547,7 @@ private List<PSResourceInfo> InstallPackages(
547547 FindHelper findHelper )
548548 {
549549 _cmdletPassedIn . WriteDebug ( "In InstallHelper::InstallPackages()" ) ;
550- List < PSResourceInfo > pkgsSuccessfullyInstalled = new List < PSResourceInfo > ( ) ;
550+ List < PSResourceInfo > pkgsSuccessfullyInstalled = new ( ) ;
551551
552552 // Install parent package to the temp directory,
553553 // Get the dependencies from the installed package,
@@ -658,7 +658,7 @@ private List<PSResourceInfo> InstallPackages(
658658 }
659659
660660 // If -WhatIf is passed in, early out.
661- if ( ! _cmdletPassedIn . ShouldProcess ( "Exit ShouldProcess ") )
661+ if ( _cmdletPassedIn . MyInvocation . BoundParameters . ContainsKey ( "WhatIf ") )
662662 {
663663 return pkgsSuccessfullyInstalled ;
664664 }
@@ -1203,7 +1203,7 @@ private bool TryExtractToDirectory(string zipPath, string extractPath, out Error
12031203 {
12041204 using ( ZipArchive archive = ZipFile . OpenRead ( zipPath ) )
12051205 {
1206- foreach ( ZipArchiveEntry entry in archive . Entries )
1206+ foreach ( ZipArchiveEntry entry in archive . Entries . Where ( entry => entry . CompressedLength > 0 ) )
12071207 {
12081208 // If a file has one or more parent directories.
12091209 if ( entry . FullName . Contains ( Path . DirectorySeparatorChar ) || entry . FullName . Contains ( Path . AltDirectorySeparatorChar ) )
@@ -1328,17 +1328,17 @@ private bool CallAcceptLicense(PSResourceInfo p, string moduleManifest, string t
13281328
13291329 if ( File . Exists ( moduleManifest ) )
13301330 {
1331- using ( StreamReader sr = new StreamReader ( moduleManifest ) )
1331+ using ( StreamReader sr = new ( moduleManifest ) )
13321332 {
13331333 var text = sr . ReadToEnd ( ) ;
13341334
13351335 var pattern = "RequireLicenseAcceptance\\ s*=\\ s*\\ $true" ;
13361336 var patternToSkip1 = "#\\ s*RequireLicenseAcceptance\\ s*=\\ s*\\ $true" ;
13371337 var patternToSkip2 = "\\ *\\ s*RequireLicenseAcceptance\\ s*=\\ s*\\ $true" ;
13381338
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 ) ;
13421342 if ( rgx . IsMatch ( text ) && ! rgxComment1 . IsMatch ( text ) && ! rgxComment2 . IsMatch ( text ) )
13431343 {
13441344 requireLicenseAcceptance = true ;
@@ -1409,14 +1409,14 @@ private bool DetectClobber(string pkgName, Hashtable parsedMetadataHashtable, ou
14091409
14101410 // Get installed modules, then get all possible paths
14111411 // 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 ) ;
14131413 IEnumerable < PSResourceInfo > pkgsAlreadyInstalled = getHelper . GetPackagesFromPath (
14141414 name : new string [ ] { "*" } ,
14151415 versionRange : VersionRange . All ,
14161416 pathsToSearch : _pathsToSearch ,
14171417 selectPrereleaseOnly : false ) ;
14181418
1419- List < string > listOfCmdlets = new List < string > ( ) ;
1419+ List < string > listOfCmdlets = new ( ) ;
14201420 if ( parsedMetadataHashtable . ContainsKey ( "CmdletsToExport" ) )
14211421 {
14221422 if ( parsedMetadataHashtable [ "CmdletsToExport" ] is object [ ] cmdletsToExport )
@@ -1430,8 +1430,8 @@ private bool DetectClobber(string pkgName, Hashtable parsedMetadataHashtable, ou
14301430
14311431 foreach ( var pkg in pkgsAlreadyInstalled )
14321432 {
1433- List < string > duplicateCmdlets = new List < string > ( ) ;
1434- List < string > duplicateCmds = new List < string > ( ) ;
1433+ List < string > duplicateCmdlets = new ( ) ;
1434+ List < string > duplicateCmds = new ( ) ;
14351435 // See if any of the cmdlets or commands in the pkg we're trying to install exist within a package that's already installed
14361436 if ( pkg . Includes . Cmdlet != null && pkg . Includes . Cmdlet . Length != 0 )
14371437 {
0 commit comments