@@ -410,7 +410,12 @@ private void CreatePackageListJson(IReadOnlyCollection<UniversalPackage> package
410
410
// Download only if needed
411
411
if ( ! Directory . Exists ( artifactToolPath ) )
412
412
{
413
- bool downloadResult = DownloadAndExtractArchive ( "ArtifactTool" , releaseInfo . Value . DownloadUri , artifactToolPath , isZip : true ) ;
413
+ bool downloadResult = DownloadAndExtractArchive (
414
+ "ArtifactTool" ,
415
+ releaseInfo . Value . DownloadUri ,
416
+ artifactToolPath ,
417
+ GetArtifactToolExeName ( ) ,
418
+ isZip : true ) ;
414
419
if ( ! downloadResult )
415
420
{
416
421
return null ;
@@ -421,8 +426,7 @@ private void CreatePackageListJson(IReadOnlyCollection<UniversalPackage> package
421
426
422
427
string ? GetArtifactToolExePath ( string dir )
423
428
{
424
- string exeName = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? "artifacttool.exe" : "artifacttool" ;
425
- string exePath = Path . Combine ( dir , exeName ) ;
429
+ string exePath = Path . Combine ( dir , GetArtifactToolExeName ( ) ) ;
426
430
if ( File . Exists ( exePath ) )
427
431
{
428
432
return exePath ;
@@ -431,6 +435,9 @@ private void CreatePackageListJson(IReadOnlyCollection<UniversalPackage> package
431
435
Log . LogError ( $ "ArtifactTool '{ exePath } ' was not found.") ;
432
436
return null ;
433
437
}
438
+
439
+ static string GetArtifactToolExeName ( )
440
+ => RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? "artifacttool.exe" : "artifacttool" ;
434
441
}
435
442
436
443
private ( string Version , string DownloadUri ) ? GetArtifactToolReleaseInfo ( string osName , string arch , string patVar )
@@ -621,7 +628,12 @@ private string GetArtifactToolReleaseInfoUrl(string osName, string arch)
621
628
// Download only if needed
622
629
if ( ! Directory . Exists ( credentialProviderDir ) )
623
630
{
624
- bool downloadResult = DownloadAndExtractArchive ( "Artifacts Credential Provider" , releaseInfo . Value . DownloadUri , credentialProviderDir , isZip : RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ) ;
631
+ bool downloadResult = DownloadAndExtractArchive (
632
+ "Artifacts Credential Provider" ,
633
+ releaseInfo . Value . DownloadUri ,
634
+ credentialProviderDir ,
635
+ GetArtifactsCredentialProviderRelativePath ( ) ,
636
+ isZip : RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ) ;
625
637
if ( ! downloadResult )
626
638
{
627
639
return null ;
@@ -638,7 +650,9 @@ private string GetArtifactToolReleaseInfoUrl(string osName, string arch)
638
650
return null ;
639
651
}
640
652
641
- string GetArtifactsCredentialProviderExePath ( string dir ) => Path . Combine ( dir , "plugins" , "netcore" , "CredentialProvider.Microsoft" , exeName ) ;
653
+ string GetArtifactsCredentialProviderExePath ( string dir ) => Path . Combine ( dir , GetArtifactsCredentialProviderRelativePath ( ) ) ;
654
+
655
+ string GetArtifactsCredentialProviderRelativePath ( ) => Path . Combine ( "plugins" , "netcore" , "CredentialProvider.Microsoft" , exeName ) ;
642
656
}
643
657
644
658
private ( string Version , string DownloadUri ) ? GetArtifactsCredentialProviderReleaseInfo ( )
@@ -737,7 +751,7 @@ private string GetArtifactToolReleaseInfoUrl(string osName, string arch)
737
751
return ( version , downloadUri ) ;
738
752
}
739
753
740
- private bool DownloadAndExtractArchive ( string displayName , string downloadUri , string path , bool isZip )
754
+ private bool DownloadAndExtractArchive ( string displayName , string downloadUri , string path , string exeRelativePath , bool isZip )
741
755
{
742
756
string ? archiveDownloadPath = null ;
743
757
string ? archiveExtractPath = null ;
@@ -766,6 +780,28 @@ private bool DownloadAndExtractArchive(string displayName, string downloadUri, s
766
780
if ( isZip )
767
781
{
768
782
ZipFile . ExtractToDirectory ( archiveDownloadPath , archiveExtractPath ) ;
783
+
784
+ // Zip archives do not preserve Unix file permissions, so we need to set the executable bit manually.
785
+ if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
786
+ {
787
+ string exePath = Path . Combine ( archiveExtractPath , exeRelativePath ) ;
788
+ if ( ! File . Exists ( exePath ) )
789
+ {
790
+ Log . LogError ( $ "Failed to set executable bit on { exePath } . File not found.") ;
791
+ return false ;
792
+ }
793
+
794
+ int exitCode = ProcessHelper . Execute (
795
+ "/bin/chmod" ,
796
+ $ "+x \" { exePath } \" ",
797
+ processStdOut : message => Log . LogMessage ( MessageImportance . Low , message ) ,
798
+ processStdErr : message => Log . LogError ( message ) ) ;
799
+ if ( exitCode != 0 )
800
+ {
801
+ Log . LogError ( $ "Failed to set executable bit on { exePath } . chmod failed with exit code: { exitCode } ") ;
802
+ return false ;
803
+ }
804
+ }
769
805
}
770
806
else
771
807
{
@@ -792,6 +828,7 @@ private bool DownloadAndExtractArchive(string displayName, string downloadUri, s
792
828
destination . Delete ( true ) ;
793
829
}
794
830
831
+ Log . LogMessage ( MessageImportance . Low , $ "Moving { archiveExtractPath } to { destination . FullName } ") ;
795
832
destination . Parent ? . Create ( ) ;
796
833
Directory . Move ( archiveExtractPath , destination . FullName ) ;
797
834
0 commit comments