From f44162e7ca83cd143f30271d12ec6c5dc6e428d5 Mon Sep 17 00:00:00 2001 From: pawelpasterz <32893017+pawelpasterz@users.noreply.github.com> Date: Wed, 14 Jul 2021 14:29:12 +0200 Subject: [PATCH] fix: Do not upload/read files when path starts with gs:// (#2075) Fixes #1971 When user provides `gs://` path in `other-files` we should not upload it again. ``` Files.readAllBytes(Paths.get(file)) ``` will never succeed when the path starts with `gs://` ## Test Plan > How do we know the code works? 1. [flank test bucket](https://console.cloud.google.com/storage/browser/flank-open-source.appspot.com/test?project=flank-open-source&pageState=(%22StorageObjectListTable%22:(%22f%22:%22%255B%255D%22))&prefix=&forceOnObjectsSortingFiltering=false) 1. run `./gradlew flankFullRun` 1. prepare config with: ``` other-files: /sdcard/[some file name]: gs://[path to file uploaded to the bucket, you can reuse existing one] ``` 1. run tests 1. go to result bucket and check if there is a file from config under `/artifacts/sdcard/` path --- .../kotlin/ftl/run/platform/android/UploadOtherFiles.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test_runner/src/main/kotlin/ftl/run/platform/android/UploadOtherFiles.kt b/test_runner/src/main/kotlin/ftl/run/platform/android/UploadOtherFiles.kt index 486fd862c3..655ab2d35e 100644 --- a/test_runner/src/main/kotlin/ftl/run/platform/android/UploadOtherFiles.kt +++ b/test_runner/src/main/kotlin/ftl/run/platform/android/UploadOtherFiles.kt @@ -4,6 +4,7 @@ import ftl.api.RemoteStorage import ftl.api.uploadToRemoteStorage import ftl.args.AndroidArgs import ftl.args.IArgs +import ftl.config.FtlConstants.GCS_PREFIX import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll @@ -24,9 +25,9 @@ internal suspend fun AndroidArgs.uploadObbFiles(): Map = corouti }.awaitAll().toMap() } -fun upload(file: String, rootGcsBucket: String, runGcsPath: String): String { - return uploadToRemoteStorage( +fun upload(file: String, rootGcsBucket: String, runGcsPath: String): String = + if (file.startsWith(GCS_PREFIX)) file + else uploadToRemoteStorage( RemoteStorage.Dir(rootGcsBucket, runGcsPath), RemoteStorage.Data(file, Files.readAllBytes(Paths.get(file))) ) -}