binhosts: Dedup binpkg uploads.

Deduplicate binpkg uploads to prevent reuploading duplicates.
Fixed reland of crrev.com/c/3821936.

BUG=b:242012416
TEST=run_tests, manually executed endpoint

Change-Id: I2b3847b6f8a371cdb2cd20ee40f0ee160f08d2a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/4000541
Tested-by: Alex Klein <saklein@chromium.org>
Reviewed-by: Cindy Lin <xcl@google.com>
Commit-Queue: Alex Klein <saklein@chromium.org>
diff --git a/api/controller/binhost.py b/api/controller/binhost.py
index 005831e..9385363 100644
--- a/api/controller/binhost.py
+++ b/api/controller/binhost.py
@@ -131,6 +131,8 @@
     if not gs.PathIsGs(uri):
         raise ValueError("Upload URI %s must be Google Storage." % uri)
 
+    package_index_paths = [f.path.path for f in input_proto.package_index_files]
+
     if config.validate_only:
         return controller.RETURN_CODE_VALID_INPUT
 
@@ -144,7 +146,9 @@
     index_path = binhost.UpdatePackageIndex(
         uploads_dir, upload_uri, upload_path, sudo=True
     )
-    upload_targets = binhost.GetPrebuiltsFiles(uploads_dir)
+    upload_targets = binhost.GetPrebuiltsFiles(
+        uploads_dir, package_index_paths=package_index_paths, sudo=True
+    )
     assert index_path.startswith(
         uploads_dir
     ), "expected index_path to start with uploads_dir"