Fix bug with WaitForArtifacts that has a side-effect that didn't matter before.

Async broke the assumption that WaitForArtifacts would only be called once.
Make the side-effect optional.

BUG=chromium:274824
TEST=Ran stage of deltas with async=True and is_synced etc + unittests.

Change-Id: I012385fe1cbeadffb7ae283051aad502576a7325
Reviewed-on: https://gerrit.chromium.org/gerrit/66149
Reviewed-by: Alex Miller <milleral@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Tested-by: Chris Sosa <sosa@chromium.org>
diff --git a/build_artifact.py b/build_artifact.py
index 88aa50d..d55e6c4 100755
--- a/build_artifact.py
+++ b/build_artifact.py
@@ -104,8 +104,12 @@
     with open(os.path.join(self.install_dir, self.marker_name), 'w') as f:
       f.write('')
 
-  def WaitForArtifactToExist(self, timeout):
-    """Waits for artifact to exist and sets self.name to appropriate name."""
+  def WaitForArtifactToExist(self, timeout, update_name=True):
+    """Waits for artifact to exist and sets self.name to appropriate name.
+
+    Args:
+      update_name: If False, don't actually update self.name.
+    """
     names = gsutil_util.GetGSNamesWithWait(
         self.name, self.archive_url, str(self), single_item=self.single_name,
         timeout=timeout)
@@ -117,9 +121,12 @@
       if len(names) > 1:
         raise ArtifactDownloadError('Too many artifacts match %s' % self.name)
 
-      self.name = names[0]
+      new_name = names[0]
     else:
-      self.name = names
+      new_name = names
+
+    if update_name:
+      self.name = new_name
 
   def _Download(self):
     """Downloads artifact from Google Storage to a local directory."""