Use FileUtils for clearing TMPDIR and move clearing function to ShellUtils from TermuxService

This commit is contained in:
agnostic-apollo
2021-04-06 06:00:41 +05:00
parent b2cd20c035
commit 8598b92dea
2 changed files with 11 additions and 10 deletions

View File

@@ -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();

View File

@@ -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);
}
}
}