Fix termux-reset

The TMPDIR was being automatically cleared and recreated even if it didn't already exist when TermuxService was stopped. This left an empty TMPDIR in the PREFIX directory when termux-reset was run and on termux restart the bootstrap wasn't installed again because PREFIX directory already existed. This resulted in a broken environment since no binaries/libs existed under PREFIX and /system/bin/sh was loaded.

This issue was created due to v0.109.
This commit is contained in:
agnostic-apollo 2021-04-20 12:39:54 +05:00
parent a6ae656c9f
commit d6eb5e3511
2 changed files with 5 additions and 2 deletions

View File

@ -157,7 +157,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas
public void onDestroy() {
Logger.logVerbose(LOG_TAG, "onDestroy");
ShellUtils.clearTermuxTMPDIR(this);
ShellUtils.clearTermuxTMPDIR(this, true);
actionReleaseWakeLock(false);
if (!mWantsToStop)

View File

@ -150,7 +150,10 @@ public class ShellUtils {
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) {