@@ -22,6 +22,7 @@ import okio.buffer
22
22
import okio.source
23
23
import java.io.File
24
24
import java.io.InterruptedIOException
25
+ import kotlin.io.path.deleteIfExists
25
26
26
27
private const val TAG_LATEST = " latest"
27
28
private const val TAG_BETA = " prerelease"
@@ -181,6 +182,10 @@ class ReleaseManager private constructor(
181
182
// set an initial download size
182
183
_uiState .value = ReleaseManagerState .InDownload (0 , releaseAsset.size)
183
184
185
+ val outputFile = getTempFile()
186
+ // clone the file instance as renameTo may move the original file
187
+ val tempFilePath = outputFile.path
188
+
184
189
try {
185
190
val fileStream = DownloadUtils .downloadStream(
186
191
httpClient,
@@ -189,23 +194,30 @@ class ReleaseManager private constructor(
189
194
_uiState .value = ReleaseManagerState .InDownload (progress, outOf)
190
195
}
191
196
197
+ outputFile.parentFile?.mkdirs()
198
+
192
199
val geodeFile = getGeodeOutputPath()
193
200
201
+ DownloadUtils .extractFileFromZipStream(
202
+ fileStream,
203
+ outputFile.outputStream(),
204
+ geodeFile.name
205
+ )
206
+
194
207
// work around a permission issue from adb push
195
208
if (geodeFile.exists()) {
196
209
geodeFile.delete()
197
210
}
198
211
199
- geodeFile.parentFile?.mkdirs()
200
-
201
- DownloadUtils .extractFileFromZipStream(
202
- fileStream,
203
- geodeFile.outputStream(),
204
- geodeFile.name
205
- )
212
+ outputFile.renameTo(geodeFile)
206
213
} catch (e: Exception ) {
207
214
sendError(e)
208
215
return
216
+ } finally {
217
+ val tempFileClone = File (tempFilePath)
218
+ try {
219
+ if (tempFileClone.exists()) tempFileClone.delete()
220
+ } catch (_: Exception ) { }
209
221
}
210
222
211
223
downloadLauncherUpdateIfNecessary()
@@ -325,6 +337,15 @@ class ReleaseManager private constructor(
325
337
return File (geodeDirectory, geodeName)
326
338
}
327
339
340
+ private fun getTempFile (): File {
341
+ val geodeName = LaunchUtils .geodeFilename
342
+ val geodeDirectory = LaunchUtils .getBaseDirectory(applicationContext)
343
+
344
+ val tempFile = File .createTempFile(geodeName, null , geodeDirectory)
345
+
346
+ return tempFile
347
+ }
348
+
328
349
/* *
329
350
* Cancels the current update job.
330
351
*/
0 commit comments