diff --git a/app/src/main/java/com/termux/app/TermuxService.java b/app/src/main/java/com/termux/app/TermuxService.java index 64ca368524..39c92023be 100644 --- a/app/src/main/java/com/termux/app/TermuxService.java +++ b/app/src/main/java/com/termux/app/TermuxService.java @@ -157,7 +157,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { public void onDestroy() { Logger.logVerbose(LOG_TAG, "onDestroy"); - ShellUtils.clearTermuxTMPDIR(this); + ShellUtils.clearTermuxTMPDIR(this, true); actionReleaseWakeLock(false); if (!mWantsToStop) diff --git a/termux-shared/src/main/java/com/termux/shared/shell/ShellUtils.java b/termux-shared/src/main/java/com/termux/shared/shell/ShellUtils.java index af32758e28..47ad08bbe7 100644 --- a/termux-shared/src/main/java/com/termux/shared/shell/ShellUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/shell/ShellUtils.java @@ -150,7 +150,10 @@ public static String getExecutableBasename(String executable) { return (lastSlash == -1) ? executable : executable.substring(lastSlash + 1); } - public static void clearTermuxTMPDIR(Context context) { + public static void clearTermuxTMPDIR(Context context, boolean onlyIfExists) { + if(onlyIfExists && !FileUtils.directoryFileExists(TermuxConstants.TERMUX_TMP_PREFIX_DIR_PATH, false)) + return; + String errmsg; errmsg = FileUtils.clearDirectory(context, "$TMPDIR", FileUtils.getCanonicalPath(TermuxConstants.TERMUX_TMP_PREFIX_DIR_PATH, null, false)); if (errmsg != null) {