Use typed file predicates in SSD truth store

ober

987ba72fcf829a87f48d139d558d846f66ec31fb

diff --git a/templates/ssd-review.ss b/templates/ssd-review.ss
index d35dda7..ca26551 100644
--- a/templates/ssd-review.ss
+++ b/templates/ssd-review.ss
@@ -7652,7 +7652,7 @@
        ""
        "    fun loadTruth(sourceKey: String): JSONObject? {"
        "        val file = truthPath(sourceKey)"
-       "        if (!file.exists()) return null"
+       "        if (!fileExists(file)) return null"
        "        return jsonObjectFromText(readLocalText(file))"
        "    }"
        ""
@@ -7682,7 +7682,7 @@
        "    }"
        ""
        "    private fun truthIndexEntry(file: File): TruthIndexEntry? {"
-       "        if (!file.exists() || !file.isFile) return null"
+       "        if (!fileIsRegular(file)) return null"
        "        return try {"
        "            val truth = jsonObjectFromText(readLocalText(file))"
        "            truthIndexEntryFromJson(file, truth, truthTime(truth) ?: file.lastModified())"
@@ -7901,7 +7901,7 @@
        "            connectTimeout = 5000"
        "            readTimeout = 30000"
        "            instanceFollowRedirects = false"
-       "            if (config.bearerToken.isNotBlank()) setRequestProperty(\"Authorization\", bearerAuthorizationHeader(config.bearerToken))"
+       "            if (remoteBearerTokenPresent(config.bearerToken)) setRequestProperty(\"Authorization\", bearerAuthorizationHeader(config.bearerToken))"
        "            setRequestProperty(\"Accept\", \"application/json\")"
        "            if (acceptGzip) setRequestProperty(\"Accept-Encoding\", \"gzip\")"
        "            if (contentType != null) setRequestProperty(\"Content-Type\", contentType)"
@@ -8037,8 +8037,8 @@
        ""
        "    fun applyLearnedGuesses(session: SsdSession): Int {"
        "        val file = File(learnedDir, \"group_examples.json\")"
-       "        if (!file.exists()) rebuildLearnedExamples()"
-       "        if (!file.exists()) return 0"
+       "        if (!fileExists(file)) rebuildLearnedExamples()"
+       "        if (!fileExists(file)) return 0"
        "        val examples = learnedExamplesFromDocument(jsonObjectFromText(readLocalText(file)))"
        "        return applyLearnedGuessesFromExamples(session, examples)"
        "    }"
@@ -8142,9 +8142,9 @@
        "        val destination = containedImportPath(entry.name)"
        "        val bytes = entry._file.inputStream().use { readBoundedBytes(it, MAX_ZIP_ENTRY_BYTES) }"
        "        return if (entry.name.endsWith(\".jsonl\")) {"
-       "            val before = if (destination.exists()) readLocalText(destination) else \"\""
+       "            val before = if (fileExists(destination)) readLocalText(destination) else \"\""
        "            mergeJsonLines(destination, bytes.decodeToString())"
-       "            !destination.exists() || readLocalText(destination) != before"
+       "            !fileExists(destination) || readLocalText(destination) != before"
        "        } else {"
        "            val text = bytes.decodeToString()"
        "            if (shouldReplaceLocal(destination, text, entry.modified)) {"
@@ -8372,7 +8372,7 @@
        "        require(remoteText.toByteArray(Charsets.UTF_8).size.toLong() <= MAX_ZIP_ENTRY_BYTES)"
        "        validateImportedText(file.name, remoteText)"
        "        val lines = linkedSetOf<String>()"
-       "        if (file.exists()) {"
+       "        if (fileExists(file)) {"
        "            readLocalText(file).lineSequence().map { it.trim() }.filter { it.isNotBlank() }.forEach { lines.add(it) }"
        "        }"
        "        remoteText.lineSequence().map { it.trim() }.filter { it.isNotBlank() }.forEach {"
@@ -8385,7 +8385,7 @@
        "    }"
        ""
        "    private fun shouldReplaceLocal(local: File, remoteText: String, remoteModified: Long): Boolean {"
-       "        if (!local.exists()) return true"
+       "        if (!fileExists(local)) return true"
        "        val localText = readLocalText(local)"
        "        if (localText == remoteText) return false"
        "        val localGenerated = jsonTime(localText)"
@@ -8415,7 +8415,7 @@
        "    }"
        ""
        "    private fun appendJsonLine(file: File, json: JSONObject) {"
-       "        val previous = if (file.exists()) readLocalText(file) else \"\""
+       "        val previous = if (fileExists(file)) readLocalText(file) else \"\""
        "        val next = previous + json.toString() + \"\\n\""
        "        require(next.toByteArray(Charsets.UTF_8).size.toLong() <= MAX_ZIP_ENTRY_BYTES) { \"Event log quota exceeded\" }"
        "        atomicWriteText(file, next)"