Skip to content

Commit 8598b92

Browse files
Use FileUtils for clearing TMPDIR and move clearing function to ShellUtils from TermuxService
1 parent b2cd20c commit 8598b92

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

app/src/main/java/com/termux/app/TermuxService.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,8 @@ public int onStartCommand(Intent intent, int flags, int startId) {
154154
@Override
155155
public void onDestroy() {
156156
Logger.logVerbose(LOG_TAG, "onDestroy");
157-
File termuxTmpDir = TermuxConstants.TERMUX_TMP_DIR;
158157

159-
if (termuxTmpDir.exists()) {
160-
try {
161-
TermuxInstaller.deleteDirectory(termuxTmpDir.getCanonicalFile());
162-
} catch (Exception e) {
163-
Logger.logStackTraceWithMessage(LOG_TAG, "Error while removing file at " + termuxTmpDir.getAbsolutePath(), e);
164-
}
165-
166-
termuxTmpDir.mkdirs();
167-
}
158+
ShellUtils.clearTermuxTMPDIR(this);
168159

169160
actionReleaseWakeLock(false);
170161
finishAllTermuxSessions();

app/src/main/java/com/termux/app/shell/ShellUtils.java

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import android.content.Context;
44

55
import com.termux.app.TermuxConstants;
6+
import com.termux.app.file.FileUtils;
7+
import com.termux.app.utils.Logger;
68
import com.termux.app.utils.PackageUtils;
79
import com.termux.app.utils.TermuxUtils;
810

@@ -143,4 +145,12 @@ public static String getExecutableBasename(String executable) {
143145
return (lastSlash == -1) ? executable : executable.substring(lastSlash + 1);
144146
}
145147

148+
public static void clearTermuxTMPDIR(Context context) {
149+
String errmsg;
150+
errmsg = FileUtils.clearDirectory(context, "$TMPDIR", FileUtils.getCanonicalPath(TermuxConstants.TERMUX_TMP_PREFIX_DIR_PATH, null, false));
151+
if (errmsg != null) {
152+
Logger.logErrorAndShowToast(context, errmsg);
153+
}
154+
}
155+
146156
}

0 commit comments

Comments
 (0)