@@ -286,7 +286,7 @@ private List<string> InstallPackage(
286286 bool isLocalRepo )
287287 {
288288 List < string > pkgsSuccessfullyInstalled = new List < string > ( ) ;
289- foreach ( PSResourceInfo p in pkgsToInstall )
289+ foreach ( PSResourceInfo pkgInfo in pkgsToInstall )
290290 {
291291 var tempInstallPath = Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) . ToString ( ) ) ;
292292 try
@@ -300,23 +300,24 @@ private List<string> InstallPackage(
300300 // TODO: are there Linux accommodations we need to consider here?
301301 dir . Attributes = dir . Attributes & ~ FileAttributes . ReadOnly ;
302302
303- _cmdletPassedIn . WriteVerbose ( string . Format ( "Begin installing package: '{0}'" , p . Name ) ) ;
303+ _cmdletPassedIn . WriteVerbose ( string . Format ( "Begin installing package: '{0}'" , pkgInfo . Name ) ) ;
304304
305305 // TODO: add progress bar here
306306
307307 // Create PackageIdentity in order to download
308- string createFullVersion = p . Version . ToString ( ) ;
309- if ( p . IsPrerelease )
308+ string createFullVersion = pkgInfo . Version . ToString ( ) ;
309+ if ( pkgInfo . IsPrerelease )
310310 {
311- createFullVersion = p . Version . ToString ( ) + "-" + p . PrereleaseLabel ;
311+ createFullVersion = pkgInfo . Version . ToString ( ) + "-" + pkgInfo . PrereleaseLabel ;
312312 }
313313
314314 if ( ! NuGetVersion . TryParse ( createFullVersion , out NuGetVersion pkgVersion ) )
315315 {
316- _cmdletPassedIn . WriteVerbose ( string . Format ( "Error parsing package '{0}' version '{1}' into a NuGetVersion" , p . Name , p . Version . ToString ( ) ) ) ;
316+ _cmdletPassedIn . WriteVerbose ( string . Format ( "Error parsing package '{0}' version '{1}' into a NuGetVersion" ,
317+ pkgInfo . Name , pkgInfo . Version . ToString ( ) ) ) ;
317318 continue ;
318319 }
319- var pkgIdentity = new PackageIdentity ( p . Name , pkgVersion ) ;
320+ var pkgIdentity = new PackageIdentity ( pkgInfo . Name , pkgVersion ) ;
320321 var cacheContext = new SourceCacheContext ( ) ;
321322
322323 if ( isLocalRepo )
@@ -352,7 +353,9 @@ private List<string> InstallPackage(
352353 result . PackageReader . CopyFiles (
353354 destination : tempInstallPath ,
354355 packageFiles : result . PackageReader . GetFiles ( ) ,
355- extractFile : ( new PackageFileExtractor ( result . PackageReader . GetFiles ( ) , packageExtractionContext . XmlDocFileSaveMode ) ) . ExtractPackageFile ,
356+ extractFile : new PackageFileExtractor (
357+ result . PackageReader . GetFiles ( ) ,
358+ packageExtractionContext . XmlDocFileSaveMode ) . ExtractPackageFile ,
356359 logger : NullLogger . Instance ,
357360 token : _cancellationToken ) ;
358361 result . Dispose ( ) ;
@@ -409,8 +412,8 @@ private List<string> InstallPackage(
409412 string tempDirNameVersion = isLocalRepo ? tempInstallPath : Path . Combine ( tempInstallPath , pkgIdentity . Id . ToLower ( ) , newVersion ) ;
410413 var version4digitNoPrerelease = pkgIdentity . Version . Version . ToString ( ) ;
411414 string moduleManifestVersion = string . Empty ;
412- var scriptPath = Path . Combine ( tempDirNameVersion , ( p . Name + ".ps1" ) ) ;
413- var modulePath = Path . Combine ( tempDirNameVersion , ( p . Name + ".psd1" ) ) ;
415+ var scriptPath = Path . Combine ( tempDirNameVersion , pkgInfo . Name + ".ps1" ) ;
416+ var modulePath = Path . Combine ( tempDirNameVersion , pkgInfo . Name + ".psd1" ) ;
414417 // Check if the package is a module or a script
415418 var isModule = File . Exists ( modulePath ) ;
416419
@@ -436,20 +439,20 @@ private List<string> InstallPackage(
436439 moduleManifestVersion = parsedMetadataHashtable [ "ModuleVersion" ] as string ;
437440
438441 // Accept License verification
439- if ( ! _savePkg && ! CallAcceptLicense ( p , moduleManifest , tempInstallPath , newVersion ) )
442+ if ( ! _savePkg && ! CallAcceptLicense ( pkgInfo , moduleManifest , tempInstallPath , newVersion ) )
440443 {
441444 continue ;
442445 }
443446
444447 // If NoClobber is specified, ensure command clobbering does not happen
445- if ( _noClobber && ! DetectClobber ( p . Name , tempDirNameVersion , parsedMetadataHashtable ) )
448+ if ( _noClobber && ! DetectClobber ( pkgInfo . Name , parsedMetadataHashtable ) )
446449 {
447450 continue ;
448451 }
449452 }
450453
451454 // Delete the extra nupkg related files that are not needed and not part of the module/script
452- DeleteExtraneousFiles ( tempInstallPath , pkgIdentity , tempDirNameVersion ) ;
455+ DeleteExtraneousFiles ( pkgIdentity , tempDirNameVersion ) ;
453456
454457 string installPath ;
455458 if ( _savePkg )
@@ -468,20 +471,29 @@ private List<string> InstallPackage(
468471
469472 if ( _includeXML )
470473 {
471- CreateMetadataXMLFile ( tempDirNameVersion , installPath , repoName , p , isModule ) ;
474+ CreateMetadataXMLFile ( tempDirNameVersion , installPath , pkgInfo , isModule ) ;
472475 }
473476
474- MoveFilesIntoInstallPath ( p , isModule , isLocalRepo , tempDirNameVersion , tempInstallPath , installPath , newVersion , moduleManifestVersion , normalizedVersionNoPrereleaseLabel , version4digitNoPrerelease , scriptPath ) ;
477+ MoveFilesIntoInstallPath (
478+ pkgInfo ,
479+ isModule ,
480+ isLocalRepo ,
481+ tempDirNameVersion ,
482+ tempInstallPath ,
483+ installPath ,
484+ newVersion ,
485+ moduleManifestVersion ,
486+ scriptPath ) ;
475487
476- _cmdletPassedIn . WriteVerbose ( String . Format ( "Successfully installed package '{0}' to location '{1}'" , p . Name , installPath ) ) ;
477- pkgsSuccessfullyInstalled . Add ( p . Name ) ;
488+ _cmdletPassedIn . WriteVerbose ( String . Format ( "Successfully installed package '{0}' to location '{1}'" , pkgInfo . Name , installPath ) ) ;
489+ pkgsSuccessfullyInstalled . Add ( pkgInfo . Name ) ;
478490 }
479491 catch ( Exception e )
480492 {
481493 _cmdletPassedIn . WriteError (
482494 new ErrorRecord (
483495 new PSInvalidOperationException (
484- message : $ "Unable to successfully install package '{ p . Name } ': '{ e . Message } '",
496+ message : $ "Unable to successfully install package '{ pkgInfo . Name } ': '{ e . Message } '",
485497 innerException : e ) ,
486498 "InstallPackageFailed" ,
487499 ErrorCategory . InvalidOperation ,
@@ -584,7 +596,7 @@ private bool CallAcceptLicense(PSResourceInfo p, string moduleManifest, string t
584596 return success ;
585597 }
586598
587- private bool DetectClobber ( string pkgName , string tempDirNameVersion , Hashtable parsedMetadataHashtable )
599+ private bool DetectClobber ( string pkgName , Hashtable parsedMetadataHashtable )
588600 {
589601 // Get installed modules, then get all possible paths
590602 bool foundClobber = false ;
@@ -608,10 +620,12 @@ private bool DetectClobber(string pkgName, string tempDirNameVersion, Hashtable
608620 duplicateCmdlets = listOfCmdlets . Where ( cmdlet => pkg . Includes . Cmdlet . Contains ( cmdlet ) ) . ToList ( ) ;
609621
610622 }
623+
611624 if ( pkg . Includes . Command != null && pkg . Includes . Command . Any ( ) )
612625 {
613626 duplicateCmds = listOfCmdlets . Where ( commands => pkg . Includes . Command . Contains ( commands , StringComparer . InvariantCultureIgnoreCase ) ) . ToList ( ) ;
614627 }
628+
615629 if ( duplicateCmdlets . Any ( ) || duplicateCmds . Any ( ) )
616630 {
617631
@@ -634,7 +648,7 @@ private bool DetectClobber(string pkgName, string tempDirNameVersion, Hashtable
634648 return foundClobber ;
635649 }
636650
637- private void CreateMetadataXMLFile ( string dirNameVersion , string installPath , string repoName , PSResourceInfo pkg , bool isModule )
651+ private void CreateMetadataXMLFile ( string dirNameVersion , string installPath , PSResourceInfo pkg , bool isModule )
638652 {
639653 // Script will have a metadata file similar to: "TestScript_InstalledScriptInfo.xml"
640654 // Modules will have the metadata file: "PSGetModuleInfo.xml"
@@ -654,14 +668,14 @@ private void CreateMetadataXMLFile(string dirNameVersion, string installPath, st
654668 }
655669 }
656670
657- private void DeleteExtraneousFiles ( string tempInstallPath , PackageIdentity pkgIdentity , string dirNameVersion )
671+ private void DeleteExtraneousFiles ( PackageIdentity pkgIdentity , string dirNameVersion )
658672 {
659673 // Deleting .nupkg SHA file, .nuspec, and .nupkg after unpacking the module
660674 var pkgIdString = pkgIdentity . ToString ( ) ;
661- var nupkgSHAToDelete = Path . Combine ( dirNameVersion , ( pkgIdString + ".nupkg.sha512" ) ) ;
662- var nuspecToDelete = Path . Combine ( dirNameVersion , ( pkgIdentity . Id + ".nuspec" ) ) ;
663- var nupkgToDelete = Path . Combine ( dirNameVersion , ( pkgIdString + ".nupkg" ) ) ;
664- var nupkgMetadataToDelete = Path . Combine ( dirNameVersion , ( pkgIdString + ".nupkg.metadata" ) ) ;
675+ var nupkgSHAToDelete = Path . Combine ( dirNameVersion , pkgIdString + ".nupkg.sha512" ) ;
676+ var nuspecToDelete = Path . Combine ( dirNameVersion , pkgIdentity . Id + ".nuspec" ) ;
677+ var nupkgToDelete = Path . Combine ( dirNameVersion , pkgIdString + ".nupkg" ) ;
678+ var nupkgMetadataToDelete = Path . Combine ( dirNameVersion , pkgIdString + ".nupkg.metadata" ) ;
665679 var contentTypesToDelete = Path . Combine ( dirNameVersion , "[Content_Types].xml" ) ;
666680 var relsDirToDelete = Path . Combine ( dirNameVersion , "_rels" ) ;
667681 var packageDirToDelete = Path . Combine ( dirNameVersion , "package" ) ;
@@ -725,25 +739,23 @@ private bool TryDeleteDirectory(
725739 }
726740
727741 private void MoveFilesIntoInstallPath (
728- PSResourceInfo p ,
742+ PSResourceInfo pkgInfo ,
729743 bool isModule ,
730744 bool isLocalRepo ,
731745 string dirNameVersion ,
732746 string tempInstallPath ,
733747 string installPath ,
734748 string newVersion ,
735749 string moduleManifestVersion ,
736- string nupkgVersion ,
737- string versionWithoutPrereleaseTag ,
738750 string scriptPath )
739751 {
740752 // Creating the proper installation path depending on whether pkg is a module or script
741- var newPathParent = isModule ? Path . Combine ( installPath , p . Name ) : installPath ;
742- var finalModuleVersionDir = isModule ? Path . Combine ( installPath , p . Name , moduleManifestVersion ) : installPath ; // versionWithoutPrereleaseTag
753+ var newPathParent = isModule ? Path . Combine ( installPath , pkgInfo . Name ) : installPath ;
754+ var finalModuleVersionDir = isModule ? Path . Combine ( installPath , pkgInfo . Name , moduleManifestVersion ) : installPath ;
743755
744756 // If script, just move the files over, if module, move the version directory over
745757 var tempModuleVersionDir = ( ! isModule || isLocalRepo ) ? dirNameVersion
746- : Path . Combine ( tempInstallPath , p . Name . ToLower ( ) , newVersion ) ;
758+ : Path . Combine ( tempInstallPath , pkgInfo . Name . ToLower ( ) , newVersion ) ;
747759
748760 _cmdletPassedIn . WriteVerbose ( string . Format ( "Installation source path is: '{0}'" , tempModuleVersionDir ) ) ;
749761 _cmdletPassedIn . WriteVerbose ( string . Format ( "Installation destination path is: '{0}'" , finalModuleVersionDir ) ) ;
@@ -774,11 +786,12 @@ private void MoveFilesIntoInstallPath(
774786 Utils . MoveDirectory ( tempModuleVersionDir , finalModuleVersionDir ) ;
775787 }
776788 }
777- else {
789+ else
790+ {
778791 if ( ! _savePkg )
779792 {
780793 // Need to delete old xml files because there can only be 1 per script
781- var scriptXML = p . Name + "_InstalledScriptInfo.xml" ;
794+ var scriptXML = pkgInfo . Name + "_InstalledScriptInfo.xml" ;
782795 _cmdletPassedIn . WriteVerbose ( string . Format ( "Checking if path '{0}' exists: " , File . Exists ( Path . Combine ( installPath , "InstalledScriptInfos" , scriptXML ) ) ) ) ;
783796 if ( File . Exists ( Path . Combine ( installPath , "InstalledScriptInfos" , scriptXML ) ) )
784797 {
@@ -790,16 +803,16 @@ private void MoveFilesIntoInstallPath(
790803 Utils . MoveFiles ( Path . Combine ( dirNameVersion , scriptXML ) , Path . Combine ( installPath , "InstalledScriptInfos" , scriptXML ) ) ;
791804
792805 // Need to delete old script file, if that exists
793- _cmdletPassedIn . WriteVerbose ( string . Format ( "Checking if path '{0}' exists: " , File . Exists ( Path . Combine ( finalModuleVersionDir , p . Name + ".ps1" ) ) ) ) ;
794- if ( File . Exists ( Path . Combine ( finalModuleVersionDir , p . Name + ".ps1" ) ) )
806+ _cmdletPassedIn . WriteVerbose ( string . Format ( "Checking if path '{0}' exists: " , File . Exists ( Path . Combine ( finalModuleVersionDir , pkgInfo . Name + ".ps1" ) ) ) ) ;
807+ if ( File . Exists ( Path . Combine ( finalModuleVersionDir , pkgInfo . Name + ".ps1" ) ) )
795808 {
796809 _cmdletPassedIn . WriteVerbose ( string . Format ( "Deleting script file" ) ) ;
797- File . Delete ( Path . Combine ( finalModuleVersionDir , p . Name + ".ps1" ) ) ;
810+ File . Delete ( Path . Combine ( finalModuleVersionDir , pkgInfo . Name + ".ps1" ) ) ;
798811 }
799812 }
800813
801- _cmdletPassedIn . WriteVerbose ( string . Format ( "Moving '{0}' to '{1}'" , scriptPath , Path . Combine ( finalModuleVersionDir , p . Name + ".ps1" ) ) ) ;
802- Utils . MoveFiles ( scriptPath , Path . Combine ( finalModuleVersionDir , p . Name + ".ps1" ) ) ;
814+ _cmdletPassedIn . WriteVerbose ( string . Format ( "Moving '{0}' to '{1}'" , scriptPath , Path . Combine ( finalModuleVersionDir , pkgInfo . Name + ".ps1" ) ) ) ;
815+ Utils . MoveFiles ( scriptPath , Path . Combine ( finalModuleVersionDir , pkgInfo . Name + ".ps1" ) ) ;
803816 }
804817 }
805818
0 commit comments