Clear folder if installation failed

Close #420
This commit is contained in:
topjohnwu 2018-03-03 22:09:05 +08:00
parent 06e6151816
commit 4132eacba0

View File

@ -42,6 +42,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
private List<String> console, logs; private List<String> console, logs;
private String mBootLocation; private String mBootLocation;
private int mode; private int mode;
private File install;
private InstallMagisk(Activity context, List<String> console, List<String> logs, Uri zip) { private InstallMagisk(Activity context, List<String> console, List<String> logs, Uri zip) {
super(context); super(context);
@ -66,10 +67,10 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
protected Boolean doInBackground(Void... voids) { protected Boolean doInBackground(Void... voids) {
MagiskManager mm = MagiskManager.get(); MagiskManager mm = MagiskManager.get();
File install = new File( install = new File(
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ?
mm.createDeviceProtectedStorageContext() : mm.createDeviceProtectedStorageContext() : mm)
mm).getFilesDir().getParent() .getFilesDir().getParent()
, "install"); , "install");
Shell.Sync.sh("rm -rf " + install); Shell.Sync.sh("rm -rf " + install);
@ -249,6 +250,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
protected void onPostExecute(Boolean result) { protected void onPostExecute(Boolean result) {
FlashActivity activity = (FlashActivity) getActivity(); FlashActivity activity = (FlashActivity) getActivity();
if (!result) { if (!result) {
Shell.Async.sh("rm -rf " + install);
console.add("! Installation failed"); console.add("! Installation failed");
activity.reboot.setVisibility(View.GONE); activity.reboot.setVisibility(View.GONE);
} }