Skip to content

Commit

Permalink
Use FileUtils for clearing TMPDIR and move clearing function to Shell…
Browse files Browse the repository at this point in the history
…Utils from TermuxService
  • Loading branch information
agnostic-apollo committed Apr 6, 2021
1 parent b2cd20c commit 8598b92
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 1 addition & 10 deletions app/src/main/java/com/termux/app/TermuxService.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,8 @@ public int onStartCommand(Intent intent, int flags, int startId) {
@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();
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/termux/app/shell/ShellUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
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;

Expand Down Expand Up @@ -143,4 +145,12 @@ public static String getExecutableBasename(String executable) {
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);
}
}

}

0 comments on commit 8598b92

Please sign in to comment.