Skip to content

Commit

Permalink
Fix current working directory default value
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
agnostic-apollo committed Feb 27, 2021
1 parent 108e4cb commit 85b2c44
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/termux/app/BackgroundJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public BackgroundJob(String cwd, String fileToExecute, final String[] args, fina

public BackgroundJob(String cwd, String fileToExecute, final String[] args, final TermuxService service, PendingIntent pendingIntent) {
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 processDescription = Arrays.toString(progArray);
Expand Down Expand Up @@ -136,7 +136,7 @@ private static void addToEnvIfPresent(List<String> environment, String name) {
static String[] buildEnvironment(boolean failSafe, String cwd) {
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<>();

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/termux/app/TermuxService.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public List<TerminalSession> getSessions() {
TerminalSession createTermSession(String executablePath, String[] arguments, String cwd, boolean failSafe) {
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);
boolean isLoginShell = false;
Expand Down

0 comments on commit 85b2c44

Please sign in to comment.