Generate SSD import validation from typed Jerboa
ober
6c64a344f9ca5fc5d5cd81e3474539ac7af66c19
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -15555,7 +15555,9 @@ truthStoreWriteRemoteTruthLocal truthStoreApplyLearnedGuessesLocal truthStoreSeedBundledTruthLocal - truthStoreContainedImportPathLocal) + truthStoreContainedImportPathLocal + truthStoreValidateImportedTextLocal + truthStoreValidateImportedFileLocal) (type AssetManager) (type Context) (type Exception) @@ -15734,6 +15736,8 @@ (kotlin-value MAX_STORAGE_BYTES)) (extern (truthStoreMaxStorageFiles) : Int32 (kotlin-value MAX_STORAGE_FILES)) + (extern (truthStoreMaxJsonlLines) : Int32 + (kotlin-value MAX_JSONL_LINES)) (extern (truthStoreBase64NoWrap) : Int32 (kotlin-value Base64 NO_WRAP)) (def (truthStoreSha256Hex (bytes : Bytes)) : String @@ -16186,7 +16190,29 @@ (truthStoreImportDirectory store (zipEntryRootKind name #\/)) - (zipEntryLeafName name #\/)))))) + (zipEntryLeafName name #\/)))) + (def (truthStoreValidateImportedTextLocal + (name : String) + (text : String)) : Unit + (if (jsonLinesFileName name) + (validateImportedJsonLinesText + text + (truthStoreMaxJsonlLines)) + (begin + (jsonObjectFromText text) + (begin)))) + (def (truthStoreValidateImportedFileLocal + (name : String) + (file : File)) : Unit + (let ((input (truthStoreFileInputStream file))) + (try-finally + (truthStoreValidateImportedTextLocal + name + (utf8->string + (readBoundedBytes + input + (truthStoreMaxZipEntryBytes)))) + (truthStoreInputStreamClose input)))))) (kotlin-file-lines "com/sfb/ssdreview/TruthStore.kt" ( @@ -16586,18 +16612,11 @@ " }" " }" "" - " private fun validateImportedFile(name: String, file: File) {" - " val text = file.inputStream().use { readBoundedBytes(it, MAX_ZIP_ENTRY_BYTES).decodeToString() }" - " validateImportedText(name, text)" - " }" + " private fun validateImportedFile(name: String, file: File) =" + " truthStoreValidateImportedFileLocal(name, file)" "" - " private fun validateImportedText(name: String, text: String) {" - " if (jsonLinesFileName(name)) {" - " validateImportedJsonLinesText(text, MAX_JSONL_LINES)" - " } else {" - " jsonObjectFromText(text)" - " }" - " }" + " private fun validateImportedText(name: String, text: String) =" + " truthStoreValidateImportedTextLocal(name, text)" "" " fun syncTree(treeUri: Uri): Pair<Int, Int> {" " val maybeTree = DocumentFile.fromTreeUri(context, treeUri)"