Skip to content

Commit

Permalink
Exclude directories when locating tty, test etc (#948)
Browse files Browse the repository at this point in the history
  • Loading branch information
lrytz committed Apr 17, 2024
1 parent 6a620e7 commit cfee77c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public boolean isPosixSystemStream(SystemStream stream) {
.start();
return p.waitFor() == 0;
} catch (Throwable t) {
Log.debug("ExecTerminalProvider failed 'test -t' for " + stream, t);
// ignore
}
return false;
Expand Down
12 changes: 8 additions & 4 deletions terminal/src/main/java/org/jline/utils/OSUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public class OSUtils {
public static String INFOCMP_COMMAND;
public static String TEST_COMMAND;

private static boolean isExecutable(File f) {
return f.canExecute() && !f.isDirectory();
}

static {
boolean cygwinOrMsys = OSUtils.IS_CYGWIN || OSUtils.IS_MSYSTEM;
String suffix = cygwinOrMsys ? ".exe" : "";
Expand All @@ -64,19 +68,19 @@ public class OSUtils {
String[] paths = path.split(File.pathSeparator);
for (String p : paths) {
File ttyFile = new File(p, "tty" + suffix);
if (tty == null && ttyFile.canExecute()) {
if (tty == null && isExecutable(ttyFile)) {
tty = ttyFile.getAbsolutePath();
}
File sttyFile = new File(p, "stty" + suffix);
if (stty == null && sttyFile.canExecute()) {
if (stty == null && isExecutable(sttyFile)) {
stty = sttyFile.getAbsolutePath();
}
File infocmpFile = new File(p, "infocmp" + suffix);
if (infocmp == null && infocmpFile.canExecute()) {
if (infocmp == null && isExecutable(infocmpFile)) {
infocmp = infocmpFile.getAbsolutePath();
}
File testFile = new File(p, "test" + suffix);
if (test == null && testFile.canExecute()) {
if (test == null && isExecutable(testFile)) {
test = testFile.getAbsolutePath();
}
}
Expand Down

0 comments on commit cfee77c

Please sign in to comment.