Skip to content

Commit 85b2c44

Browse files
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`.
1 parent 108e4cb commit 85b2c44

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public BackgroundJob(String cwd, String fileToExecute, final String[] args, fina
3636

3737
public BackgroundJob(String cwd, String fileToExecute, final String[] args, final TermuxService service, PendingIntent pendingIntent) {
3838
String[] env = buildEnvironment(false, cwd);
39-
if (cwd == null) cwd = TermuxService.HOME_PATH;
39+
if (cwd == null || cwd.isEmpty()) cwd = TermuxService.HOME_PATH;
4040

4141
final String[] progArray = setupProcessArgs(fileToExecute, args);
4242
final String processDescription = Arrays.toString(progArray);
@@ -136,7 +136,7 @@ private static void addToEnvIfPresent(List<String> environment, String name) {
136136
static String[] buildEnvironment(boolean failSafe, String cwd) {
137137
new File(TermuxService.HOME_PATH).mkdirs();
138138

139-
if (cwd == null) cwd = TermuxService.HOME_PATH;
139+
if (cwd == null || cwd.isEmpty()) cwd = TermuxService.HOME_PATH;
140140

141141
List<String> environment = new ArrayList<>();
142142

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public List<TerminalSession> getSessions() {
282282
TerminalSession createTermSession(String executablePath, String[] arguments, String cwd, boolean failSafe) {
283283
new File(HOME_PATH).mkdirs();
284284

285-
if (cwd == null) cwd = HOME_PATH;
285+
if (cwd == null || cwd.isEmpty()) cwd = HOME_PATH;
286286

287287
String[] env = BackgroundJob.buildEnvironment(failSafe, cwd);
288288
boolean isLoginShell = false;

0 commit comments

Comments
 (0)