Generate SSD remote dump pulls from typed Jerboa
ober
3578984f1981c9bfef08869ed7c8806584690684
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -15565,7 +15565,8 @@ truthStoreTruthTimeLocal truthStoreShouldReplaceLocal truthStoreSaveTruthSnapshotLocal - truthStoreMergeJsonLinesLocal) + truthStoreMergeJsonLinesLocal + truthStorePullRemoteDumpLocal) (type AssetManager) (type Any) (type Context) @@ -15626,6 +15627,14 @@ (store : TruthStore) (input : InputStream)) : Int32 (kotlin-member-call importZip)) + (extern (truthStoreOpenPinnedConnectionRaw + (store : TruthStore) + (relative : String) + (method : String) + (outputBytes : (Nullable Int)) + (contentType : (Nullable String)) + (acceptGzip : Bool)) : HttpsURLConnection + (kotlin-member-call openPinnedConnection)) (extern (truthStoreSaveTruthSnapshotRaw (store : TruthStore) (truth : JSONObject)) : File @@ -15691,6 +15700,19 @@ (extern (truthStoreConnectionContentLength (connection : HttpsURLConnection)) : Int (kotlin-member-get contentLengthLong)) + (extern (truthStoreConnectionResponseCode + (connection : HttpsURLConnection)) : Int32 + (kotlin-member-get responseCode)) + (extern (truthStoreConnectionErrorStream + (connection : HttpsURLConnection)) : (Nullable InputStream) + (kotlin-member-get errorStream)) + (extern (truthStoreConnectionDisconnect + (connection : HttpsURLConnection)) : Unit + (kotlin-member-call disconnect)) + (extern (truthStoreConnectionContentLengthExceedsLimit + (connection : HttpsURLConnection) + (limit : Int)) : Bool + (kotlin-call connectionContentLengthExceedsLimit)) (extern (truthStoreLimitedInputStream (input : InputStream) (limit : Int)) : InputStream @@ -15777,6 +15799,8 @@ (kotlin-value MAX_HTTP_TEXT_BYTES)) (extern (truthStoreMaxHttpCompressedBytes) : Int (kotlin-value MAX_HTTP_COMPRESSED_BYTES)) + (extern (truthStoreMaxRemoteZipBytes) : Int + (kotlin-value MAX_REMOTE_ZIP_BYTES)) (extern (truthStoreMaxStorageBytes) : Int (kotlin-value MAX_STORAGE_BYTES)) (extern (truthStoreMaxStorageFiles) : Int32 @@ -16442,7 +16466,44 @@ (truthStoreAtomicWriteTextRaw store file - merged))))))))) + merged))))))) + (def (truthStorePullRemoteDumpLocal + (store : TruthStore)) : Int32 + (let ((connection + (truthStoreOpenPinnedConnectionRaw + store + "dump.zip?scope=app" + "GET" + (nullable-none Int) + (nullable-none String) + #f))) + (try-finally + (let ((code + (truthStoreConnectionResponseCode connection))) + (begin + (if (httpStatusFailed code) + (begin + (closeInputStreamIfPresent + (truthStoreConnectionErrorStream connection)) + (throw + (truthStoreIllegalStateException + (httpStatusMessage code)) + Unit)) + (begin)) + (if (truthStoreConnectionContentLengthExceedsLimit + connection + (truthStoreMaxRemoteZipBytes)) + (throw + (truthStoreIllegalStateException + "Remote ZIP exceeds compressed-byte limit") + Unit) + (begin)) + (let ((input + (truthStoreConnectionInputStream connection))) + (try-finally + (truthStoreImportZipRaw store input) + (truthStoreInputStreamClose input))))) + (truthStoreConnectionDisconnect connection)))))) (kotlin-file-lines "com/sfb/ssdreview/TruthStore.kt" ( @@ -16606,7 +16667,7 @@ " private fun remoteUrl(relative: String): URL =" " truthStoreRemoteUrlLocal(remoteConfig, relative)" "" - " private fun openPinnedConnection(" + " internal fun openPinnedConnection(" " relative: String," " method: String," " outputBytes: Long? = null," @@ -16842,22 +16903,8 @@ " return imported to exported" " }" "" - " fun pullRemoteDump(): Int {" - " val connection = openPinnedConnection(\"dump.zip?scope=app\", \"GET\")" - " try {" - " val code = connection.responseCode" - " if (httpStatusFailed(code)) {" - " closeInputStreamIfPresent(connection.errorStream)" - " throw IllegalStateException(httpStatusMessage(code))" - " }" - " if (connectionContentLengthExceedsLimit(connection, MAX_REMOTE_ZIP_BYTES)) {" - " throw IllegalStateException(\"Remote ZIP exceeds compressed-byte limit\")" - " }" - " return connection.inputStream.use { importZip(it) }" - " } finally {" - " connection.disconnect()" - " }" - " }" + " fun pullRemoteDump(): Int =" + " truthStorePullRemoteDumpLocal(this)" "" " fun pushRemoteDump(): Int {" " val archive = File.createTempFile(\"ssd-upload-\", \".zip\", context.cacheDir)"