replace use of createTempFile with manual naming

This commit is contained in:
Chloe committed 2026-02-25 14:18:31 -07:00
1 parent f17500ef7b
commit ce98734bb9
2 files changed
+19 -12

No files matched your search

@@ -182,9 +182,10 @@ class ReleaseManager private constructor(
// clone the file instance as renameTo may move the original file // clone the file instance as renameTo may move the original file
val tempFilePath = outputFile.path val tempFilePath = outputFile.path
try { val geodeFile = getGeodeOutputPath()
val geodeFile = getGeodeOutputPath()
try {
// tempFile should be in same path as geodeFile
val geodeParent = geodeFile.parentFile val geodeParent = geodeFile.parentFile
if (geodeParent != null && !geodeParent.exists()) { if (geodeParent != null && !geodeParent.exists()) {
geodeParent.mkdirs() geodeParent.mkdirs()
@@ -199,7 +200,7 @@ class ReleaseManager private constructor(
onResponse = { body -> onResponse = { body ->
DownloadUtils.extractFileFromZipStream( DownloadUtils.extractFileFromZipStream(
body.byteStream(), body.byteStream(),
outputFile.outputStream(), outputFile,
geodeFile.name geodeFile.name
) )
@@ -397,7 +398,14 @@ class ReleaseManager private constructor(
val geodeName = LaunchUtils.geodeFilename val geodeName = LaunchUtils.geodeFilename
val geodeDirectory = LaunchUtils.getBaseDirectory(applicationContext) val geodeDirectory = LaunchUtils.getBaseDirectory(applicationContext)
val tempFile = File.createTempFile(geodeName, null, geodeDirectory) val alphabet = ('A'..'Z') + ('a'..'z') + ('0'..'9')
val suffix = buildString(8) {
repeat(8) { append(alphabet.random()) }
}
val tmpName = "tmp-$suffix.$geodeName"
val tempFile = File(geodeDirectory, tmpName)
return tempFile return tempFile
} }
@@ -77,23 +77,22 @@ object DownloadUtils {
* *
* inputStream and outputStream are both closed after this function executes * inputStream and outputStream are both closed after this function executes
*/ */
suspend fun extractFileFromZipStream(inputStream: InputStream, outputStream: OutputStream, zipPath: String) { suspend fun extractFileFromZipStream(inputStream: InputStream, output: File, zipPath: String) {
// note to self: ZipInputStreams are a little silly // note to self: ZipInputStreams are a little silly
// (runInterruptible allows it to cancel, otherwise it waits for the stream to finish) // (runInterruptible allows it to cancel, otherwise it waits for the stream to finish)
runInterruptible { runInterruptible {
inputStream.use { inputStream.use { input ->
outputStream.use { output.outputStream().use { out ->
// nice indentation // nice indentation
val zip = ZipInputStream(inputStream) ZipInputStream(input).use { zip ->
zip.use { var entry = zip.nextEntry
var entry = it.nextEntry
while (entry != null) { while (entry != null) {
if (entry.name == zipPath) { if (entry.name == zipPath) {
it.copyTo(outputStream) zip.copyTo(out)
return@runInterruptible return@runInterruptible
} }
entry = it.nextEntry entry = zip.nextEntry
} }
// no matching entries found, throw exception // no matching entries found, throw exception