Fix current working directory default value

This commit fixes the issue when `cwd` is empty and is passed to `Runtime.getRuntime().exec(progArray, env, new File(cwd));`, it raises the `No such file or directory` exceptions when targeting sdk `29`.
This commit is contained in:
agnostic-apollo
2021-02-27 13:22:09 +05:00
parent 108e4cb391
commit 85b2c44ac7
2 changed files with 3 additions and 3 deletions

View File

@@ -36,7 +36,7 @@ public final class BackgroundJob {
public BackgroundJob(String cwd, String fileToExecute, final String[] args, final TermuxService service, PendingIntent pendingIntent) { public BackgroundJob(String cwd, String fileToExecute, final String[] args, final TermuxService service, PendingIntent pendingIntent) {
String[] env = buildEnvironment(false, cwd); String[] env = buildEnvironment(false, cwd);
if (cwd == null) cwd = TermuxService.HOME_PATH; if (cwd == null || cwd.isEmpty()) cwd = TermuxService.HOME_PATH;
final String[] progArray = setupProcessArgs(fileToExecute, args); final String[] progArray = setupProcessArgs(fileToExecute, args);
final String processDescription = Arrays.toString(progArray); final String processDescription = Arrays.toString(progArray);
@@ -136,7 +136,7 @@ public final class BackgroundJob {
static String[] buildEnvironment(boolean failSafe, String cwd) { static String[] buildEnvironment(boolean failSafe, String cwd) {
new File(TermuxService.HOME_PATH).mkdirs(); new File(TermuxService.HOME_PATH).mkdirs();
if (cwd == null) cwd = TermuxService.HOME_PATH; if (cwd == null || cwd.isEmpty()) cwd = TermuxService.HOME_PATH;
List<String> environment = new ArrayList<>(); List<String> environment = new ArrayList<>();

View File

@@ -282,7 +282,7 @@ public final class TermuxService extends Service implements SessionChangedCallba
TerminalSession createTermSession(String executablePath, String[] arguments, String cwd, boolean failSafe) { TerminalSession createTermSession(String executablePath, String[] arguments, String cwd, boolean failSafe) {
new File(HOME_PATH).mkdirs(); new File(HOME_PATH).mkdirs();
if (cwd == null) cwd = HOME_PATH; if (cwd == null || cwd.isEmpty()) cwd = HOME_PATH;
String[] env = BackgroundJob.buildEnvironment(failSafe, cwd); String[] env = BackgroundJob.buildEnvironment(failSafe, cwd);
boolean isLoginShell = false; boolean isLoginShell = false;