From 1af186bc6650d5b3ab355614096a7e7eb2de4f9b Mon Sep 17 00:00:00 2001
From: Matt Mitchell <mmitche@microsoft.com>
Date: Tue, 22 Aug 2023 13:45:48 -0700
Subject: [PATCH] Avoid attempting to download from exteranl URIs in Product
 Source Build mode (#17237)

---
 src/redist/targets/GenerateLayout.targets | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/redist/targets/GenerateLayout.targets b/src/redist/targets/GenerateLayout.targets
index f12dd495f..899b46f78 100644
--- a/src/redist/targets/GenerateLayout.targets
+++ b/src/redist/targets/GenerateLayout.targets
@@ -368,27 +368,32 @@
            with shared metadata DownloadDestination and potentially the encoded key token for the private url.
            Then use task batching to send batched itemgroups to the DownloadFile task that have the same
            DownloadDestination. -->
-      
+
       <UrisToDownload Include="%(ComponentToDownload.BaseUrl)/%(ComponentToDownload.DownloadFileName)" Condition="'%(ComponentToDownload.ShouldDownload)' == 'true'">
         <ShouldDownload>%(ComponentToDownload.ShouldDownload)</ShouldDownload>
         <DownloadDestination>%(ComponentToDownload.DownloadDestination)</DownloadDestination>
       </UrisToDownload>
-      <UrisToDownload Include="$([System.String]::Copy('%(ComponentToDownload.BaseUrl)').Replace($(PublicBaseURL), 'https://dotnetbuilds.blob.core.windows.net/public/'))/%(ComponentToDownload.DownloadFileName)" Condition="'%(ComponentToDownload.ShouldDownload)' == 'true'">
+    </ItemGroup>
+
+    <!-- If building in product source build mode, there is no need to attempt the external URIs. These are not desired,
+            and won't work anyway because the source build file URI doesn't use the same structure as the storage accounts.
+            For example, the dotnetbuilds uri for 'file:///vmr/dotnet2/artifacts/obj/x64/Release/blob-feed/assets//aspnetcore_base_runtime.version'
+            would end up 'https://dotnetbuilds.blob.core.windows.net/public//dotnet-runtime-8.0.0-rc.1.23381.3-centos.8-x64.tar.gz'. This is
+            missing the runtime version number directory. -->
+    <ItemGroup Condition="'$(DotNetBuildFromSourceFlavor)' != 'Product'">
+      <UrisToDownload Include="$([System.String]::Copy('%(ComponentToDownload.BaseUrl)').Replace($(PublicBaseURL), 'https://dotnetbuilds.blob.core.windows.net/public/'))/%(ComponentToDownload.DownloadFileName)"
+                      Condition="'%(ComponentToDownload.ShouldDownload)' == 'true'">
         <ShouldDownload>%(ComponentToDownload.ShouldDownload)</ShouldDownload>
         <DownloadDestination>%(ComponentToDownload.DownloadDestination)</DownloadDestination>
       </UrisToDownload>
-      <UrisToDownload Include="%(ComponentToDownload.PrivateBaseUrl)/%(ComponentToDownload.DownloadFileName)" Condition="'%(ComponentToDownload.ShouldDownload)' == 'true' and '$(DotNetRuntimeSourceFeedKey)' != ''">
+      <UrisToDownload Include="%(ComponentToDownload.PrivateBaseUrl)/%(ComponentToDownload.DownloadFileName)"
+                      Condition="'%(ComponentToDownload.ShouldDownload)' == 'true' and '$(DotNetRuntimeSourceFeedKey)' != ''">
         <ShouldDownload>%(ComponentToDownload.ShouldDownload)</ShouldDownload>
         <DownloadDestination>%(ComponentToDownload.DownloadDestination)</DownloadDestination>
         <token>$(DotNetRuntimeSourceFeedKey)</token>
       </UrisToDownload>
-      <UrisToDownload Include="$([System.String]::Copy('%(ComponentToDownload.PrivateBaseUrl)').Replace($(InternalBaseURL), 'https://dotnetbuilds.blob.core.windows.net/internal/'))/%(ComponentToDownload.DownloadFileName)" Condition="'%(ComponentToDownload.ShouldDownload)' == 'true' and '$(DotNetRuntimeSourceFeedKey)' != ''">
-        <ShouldDownload>%(ComponentToDownload.ShouldDownload)</ShouldDownload>
-        <DownloadDestination>%(ComponentToDownload.DownloadDestination)</DownloadDestination>
-        <token>$(dotnetbuilds-internal-container-read-token-base64)</token>
-      </UrisToDownload>
     </ItemGroup>
-    
+
     <DownloadFile Condition=" '@(UrisToDownload)' != '' and %(ShouldDownload)"
                   Uris="@(UrisToDownload)"
                   DestinationPath="%(DownloadDestination)" />