remote: small refactoring that splits download and spawn result

Closes #7792.

PiperOrigin-RevId: 239608769
diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java
index edc5088..9b489d1 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java
@@ -196,10 +196,8 @@
             acceptCachedResult = false;
           } else {
             try (SilentCloseable c = Profiler.instance().profile("Remote.downloadRemoteResults")) {
-              return downloadRemoteResults(cachedResult, context.getFileOutErr())
-                  .setCacheHit(true)
-                  .setRunnerName("remote cache hit")
-                  .build();
+              remoteCache.download(cachedResult, execRoot, context.getFileOutErr());
+              return createSpawnResult(cachedResult.getExitCode(), /* cacheHit= */ true);
             } catch (CacheNotFoundException e) {
               // No cache hit, so we fall through to local or remote execution.
               // We set acceptCachedResult to false in order to force the action re-execution.
@@ -251,7 +249,8 @@
 
               FileOutErr outErr = context.getFileOutErr();
               String message = reply.getMessage();
-              if ((reply.getResult().getExitCode() != 0
+              ActionResult actionResult = reply.getResult();
+              if ((actionResult.getExitCode() != 0
                       || reply.getStatus().getCode() != Code.OK.value())
                   && !message.isEmpty()) {
                 outErr.printErr(message + "\n");
@@ -264,11 +263,9 @@
 
               try (SilentCloseable c =
                   Profiler.instance().profile("Remote.downloadRemoteResults")) {
-                return downloadRemoteResults(reply.getResult(), outErr)
-                    .setRunnerName(reply.getCachedResult() ? "remote cache hit" : getName())
-                    .setCacheHit(reply.getCachedResult())
-                    .build();
+                remoteCache.download(actionResult, execRoot, outErr);
               }
+              return createSpawnResult(actionResult.getExitCode(), reply.getCachedResult());
             });
       } catch (IOException e) {
         return execLocallyAndUploadOrFail(
@@ -330,13 +327,13 @@
     }
   }
 
-  private SpawnResult.Builder downloadRemoteResults(ActionResult result, FileOutErr outErr)
-      throws ExecException, IOException, InterruptedException {
-    remoteCache.download(result, execRoot, outErr);
-    int exitCode = result.getExitCode();
+  private SpawnResult createSpawnResult(int exitCode, boolean cacheHit) {
     return new SpawnResult.Builder()
         .setStatus(exitCode == 0 ? Status.SUCCESS : Status.NON_ZERO_EXIT)
-        .setExitCode(exitCode);
+        .setExitCode(exitCode)
+        .setRunnerName(cacheHit ? getName() + " cache hit" : getName())
+        .setCacheHit(cacheHit)
+        .build();
   }
 
   private SpawnResult execLocally(Spawn spawn, SpawnExecutionContext context)