@@ -1338,7 +1338,6 @@ private bool CallAcceptLicense(PSResourceInfo p, string moduleManifest, string t
1338
1338
_cmdletPassedIn . WriteDebug ( "In InstallHelper::CallAcceptLicense()" ) ;
1339
1339
error = null ;
1340
1340
var requireLicenseAcceptance = false ;
1341
- var success = true ;
1342
1341
1343
1342
if ( File . Exists ( moduleManifest ) )
1344
1343
{
@@ -1366,22 +1365,44 @@ private bool CallAcceptLicense(PSResourceInfo p, string moduleManifest, string t
1366
1365
if ( ! _acceptLicense )
1367
1366
{
1368
1367
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
+ }
1370
1392
1371
- if ( ! File . Exists ( LicenseFilePath ) )
1393
+ if ( ! foundLicense )
1372
1394
{
1373
1395
error = new ErrorRecord (
1374
1396
new ArgumentException ( $ "Package '{ p . Name } ' could not be installed: License.txt not found. License.txt must be provided when user license acceptance is required.") ,
1375
1397
"LicenseTxtNotFound" ,
1376
1398
ErrorCategory . ObjectNotFound ,
1377
- _cmdletPassedIn ) ; ;
1378
- success = false ;
1399
+ _cmdletPassedIn ) ;
1379
1400
1380
- return success ;
1401
+ return false ;
1381
1402
}
1382
1403
1383
1404
// Otherwise read LicenseFile
1384
- string licenseText = System . IO . File . ReadAllText ( LicenseFilePath ) ;
1405
+ string licenseText = File . ReadAllText ( LicenseFilePath ) ;
1385
1406
var acceptanceLicenseQuery = $ "Do you accept the license terms for module '{ p . Name } '?";
1386
1407
var message = licenseText + "\r \n " + acceptanceLicenseQuery ;
1387
1408
@@ -1404,12 +1425,13 @@ private bool CallAcceptLicense(PSResourceInfo p, string moduleManifest, string t
1404
1425
"ForceAcceptLicense" ,
1405
1426
ErrorCategory . InvalidArgument ,
1406
1427
_cmdletPassedIn ) ;
1407
- success = false ;
1428
+
1429
+ return false ;
1408
1430
}
1409
1431
}
1410
1432
}
1411
1433
1412
- return success ;
1434
+ return true ;
1413
1435
}
1414
1436
1415
1437
/// <summary>
0 commit comments