diff --git a/app/src/main/java/com/termux/app/TermuxService.java b/app/src/main/java/com/termux/app/TermuxService.java index 3bdd979d..77779b6c 100644 --- a/app/src/main/java/com/termux/app/TermuxService.java +++ b/app/src/main/java/com/termux/app/TermuxService.java @@ -154,17 +154,8 @@ public final class TermuxService extends Service { @Override public void onDestroy() { Logger.logVerbose(LOG_TAG, "onDestroy"); - File termuxTmpDir = TermuxConstants.TERMUX_TMP_DIR; - if (termuxTmpDir.exists()) { - try { - TermuxInstaller.deleteDirectory(termuxTmpDir.getCanonicalFile()); - } catch (Exception e) { - Logger.logStackTraceWithMessage(LOG_TAG, "Error while removing file at " + termuxTmpDir.getAbsolutePath(), e); - } - - termuxTmpDir.mkdirs(); - } + ShellUtils.clearTermuxTMPDIR(this); actionReleaseWakeLock(false); finishAllTermuxSessions(); diff --git a/app/src/main/java/com/termux/app/shell/ShellUtils.java b/app/src/main/java/com/termux/app/shell/ShellUtils.java index 838e7c84..a6fbefe3 100644 --- a/app/src/main/java/com/termux/app/shell/ShellUtils.java +++ b/app/src/main/java/com/termux/app/shell/ShellUtils.java @@ -3,6 +3,8 @@ package com.termux.app.shell; import android.content.Context; import com.termux.app.TermuxConstants; +import com.termux.app.file.FileUtils; +import com.termux.app.utils.Logger; import com.termux.app.utils.PackageUtils; import com.termux.app.utils.TermuxUtils; @@ -143,4 +145,12 @@ public class ShellUtils { return (lastSlash == -1) ? executable : executable.substring(lastSlash + 1); } + public static void clearTermuxTMPDIR(Context context) { + String errmsg; + errmsg = FileUtils.clearDirectory(context, "$TMPDIR", FileUtils.getCanonicalPath(TermuxConstants.TERMUX_TMP_PREFIX_DIR_PATH, null, false)); + if (errmsg != null) { + Logger.logErrorAndShowToast(context, errmsg); + } + } + }