fix: Delete cached APK only after successful patch (#2331)

This commit is contained in:
Benjamin 2024-12-23 16:48:57 -08:00 committed by GitHub
parent 1d6b074856
commit 4ba7ec1854
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 7 deletions

View File

@ -175,13 +175,6 @@ class PatcherAPI {
final File inApkFile = File('${workDir.path}/in.apk');
await File(apkFilePath).copy(inApkFile.path);
if (isFromStorage) {
// The selected apk was copied to cacheDir by the file picker, so it's not needed anymore.
// rename() can't be used here, as Android system also counts the size of files moved out from cacheDir
// as part of the app's cache size.
File(apkFilePath).delete();
}
outFile = File('${workDir.path}/out.apk');
final Directory tmpDir =

View File

@ -1,4 +1,6 @@
// ignore_for_file: use_build_context_synchronously
import 'dart:io';
import 'package:device_apps/device_apps.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
@ -566,6 +568,10 @@ class InstallerViewModel extends BaseViewModel {
Future<void> cleanPatcher() async {
try {
_patcherAPI.cleanPatcher();
if (_app.isFromStorage) {
// The selected apk was copied to cacheDir by the file picker, so it's not needed anymore.
File(_app.apkFilePath).delete();
}
locator<PatcherViewModel>().selectedApp = null;
locator<PatcherViewModel>().selectedPatches.clear();
locator<PatcherViewModel>().notifyListeners();