Skip to content

Commit

Permalink
fix: Do not upload/read files when path starts with gs:// (#2075)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pawelpasterz authored Jul 14, 2021
1 parent 1ca2f77 commit f44162e
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,9 +25,9 @@ internal suspend fun AndroidArgs.uploadObbFiles(): Map<String, String> = 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)))
)
}

0 comments on commit f44162e

Please sign in to comment.