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
val tempFilePath = outputFile.path
try {
val geodeFile = getGeodeOutputPath()
val geodeFile = getGeodeOutputPath()
try {
// tempFile should be in same path as geodeFile
val geodeParent = geodeFile.parentFile
if (geodeParent != null && !geodeParent.exists()) {
geodeParent.mkdirs()
@@ -199,7 +200,7 @@ class ReleaseManager private constructor(
onResponse = { body ->
DownloadUtils.extractFileFromZipStream(
body.byteStream(),
outputFile.outputStream(),
outputFile,
geodeFile.name
)
@@ -397,7 +398,14 @@ class ReleaseManager private constructor(
val geodeName = LaunchUtils.geodeFilename
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
}
@@ -77,23 +77,22 @@ object DownloadUtils {
*
* 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
// (runInterruptible allows it to cancel, otherwise it waits for the stream to finish)
runInterruptible {
inputStream.use {
outputStream.use {
inputStream.use { input ->
output.outputStream().use { out ->
// nice indentation
val zip = ZipInputStream(inputStream)
zip.use {
var entry = it.nextEntry
ZipInputStream(input).use { zip ->
var entry = zip.nextEntry
while (entry != null) {
if (entry.name == zipPath) {
it.copyTo(outputStream)
zip.copyTo(out)
return@runInterruptible
}
entry = it.nextEntry
entry = zip.nextEntry
}
// no matching entries found, throw exception