@@ -1338,7 +1338,6 @@ private bool CallAcceptLicense(PSResourceInfo p, string moduleManifest, string t
13381338 _cmdletPassedIn . WriteDebug ( "In InstallHelper::CallAcceptLicense()" ) ;
13391339 error = null ;
13401340 var requireLicenseAcceptance = false ;
1341- var success = true ;
13421341
13431342 if ( File . Exists ( moduleManifest ) )
13441343 {
@@ -1366,22 +1365,44 @@ private bool CallAcceptLicense(PSResourceInfo p, string moduleManifest, string t
13661365 if ( ! _acceptLicense )
13671366 {
13681367 var PkgTempInstallPath = Path . Combine ( tempInstallPath , p . Name , newVersion ) ;
1369- var LicenseFilePath = Path . Combine ( PkgTempInstallPath , "License.txt" ) ;
1368+ if ( ! Directory . Exists ( PkgTempInstallPath ) )
1369+ {
1370+ error = new ErrorRecord (
1371+ new ArgumentException ( $ "Package '{ p . Name } ' could not be installed: Temporary installation path does not exist.") ,
1372+ "TempPathNotFound" ,
1373+ ErrorCategory . ObjectNotFound ,
1374+ _cmdletPassedIn ) ;
1375+
1376+ return false ;
1377+ }
1378+
1379+ string [ ] files = Directory . GetFiles ( PkgTempInstallPath ) ;
1380+
1381+ bool foundLicense = false ;
1382+ string LicenseFilePath = string . Empty ;
1383+ foreach ( string file in files )
1384+ {
1385+ if ( string . Equals ( Path . GetFileName ( file ) , "License.txt" , StringComparison . OrdinalIgnoreCase ) )
1386+ {
1387+ foundLicense = true ;
1388+ LicenseFilePath = Path . GetFullPath ( file ) ;
1389+ break ;
1390+ }
1391+ }
13701392
1371- if ( ! File . Exists ( LicenseFilePath ) )
1393+ if ( ! foundLicense )
13721394 {
13731395 error = new ErrorRecord (
13741396 new ArgumentException ( $ "Package '{ p . Name } ' could not be installed: License.txt not found. License.txt must be provided when user license acceptance is required.") ,
13751397 "LicenseTxtNotFound" ,
13761398 ErrorCategory . ObjectNotFound ,
1377- _cmdletPassedIn ) ; ;
1378- success = false ;
1399+ _cmdletPassedIn ) ;
13791400
1380- return success ;
1401+ return false ;
13811402 }
13821403
13831404 // Otherwise read LicenseFile
1384- string licenseText = System . IO . File . ReadAllText ( LicenseFilePath ) ;
1405+ string licenseText = File . ReadAllText ( LicenseFilePath ) ;
13851406 var acceptanceLicenseQuery = $ "Do you accept the license terms for module '{ p . Name } '?";
13861407 var message = licenseText + "\r \n " + acceptanceLicenseQuery ;
13871408
@@ -1404,12 +1425,13 @@ private bool CallAcceptLicense(PSResourceInfo p, string moduleManifest, string t
14041425 "ForceAcceptLicense" ,
14051426 ErrorCategory . InvalidArgument ,
14061427 _cmdletPassedIn ) ;
1407- success = false ;
1428+
1429+ return false ;
14081430 }
14091431 }
14101432 }
14111433
1412- return success ;
1434+ return true ;
14131435 }
14141436
14151437 /// <summary>
0 commit comments