Skip to content

Commit

Permalink
Merge branch 'jruby-9.1' into psych_3_update
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Apr 16, 2018
2 parents 17a9008 + 64cfd1e commit f5f6d16
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
30 changes: 27 additions & 3 deletions core/src/main/java/org/jruby/util/ShellLauncher.java
Expand Up @@ -411,14 +411,38 @@ private static File findPathFile(Ruby runtime, String fname, String[] path, bool
return pathFile;
}

/**
* This is an older version of the path-finding logic used by our pure-Java process launching in backquote,
* system, etc. The newer version below, used by native process launching, appears to break execution of commands
* in the current working directory, e.g. "./testapp".
*
* MRI: Older version of logic for dln_find_exe_r used by popen logic
*/
public static File findPathExecutable(Ruby runtime, String fname) {
RubyHash env = (RubyHash) runtime.getObject().getConstant("ENV");
IRubyObject pathObject = env.op_aref(runtime.getCurrentContext(), RubyString.newString(runtime, PATH_ENV));
return findPathExecutable(runtime, fname, pathObject);
String[] pathNodes = null;
if (pathObject == null) {
pathNodes = DEFAULT_PATH; // ASSUME: not modified by callee
}
else {
String pathSeparator = System.getProperty("path.separator");
String path = pathObject.toString();
if (Platform.IS_WINDOWS) {
// Windows-specific behavior
path = "." + pathSeparator + path;
}
pathNodes = path.split(pathSeparator);
}
return findPathFile(runtime, fname, pathNodes, true);
}

// MRI: Hopefully close to dln_find_exe_r used by popen logic
public static File findPathExecutable(Ruby runtime, String fname, IRubyObject pathObject) {
/**
* Search for the given executable using the given PATH or one provided by system defaults.
*
* This is the updated version of MRI: dln_find_exe_r logic.
*/
public static File dlnFindExe(Ruby runtime, String fname, IRubyObject pathObject) {
String[] pathNodes;

if (pathObject == null || pathObject.isNil()) {
Expand Down
6 changes: 1 addition & 5 deletions core/src/main/java/org/jruby/util/io/PopenExecutor.java
Expand Up @@ -4,7 +4,6 @@
import jnr.constants.platform.Fcntl;
import jnr.constants.platform.OpenFlags;
import jnr.enxio.channels.NativeDeviceChannel;
import jnr.enxio.channels.NativeSelectableChannel;
import jnr.posix.SpawnAttribute;
import jnr.posix.SpawnFileAction;
import org.jcodings.transcode.EConvFlags;
Expand All @@ -21,7 +20,6 @@
import org.jruby.RubyString;
import org.jruby.RubySymbol;
import org.jruby.api.API;
import org.jruby.common.IRubyWarnings;
import org.jruby.exceptions.RaiseException;
import org.jruby.ext.fcntl.FcntlLibrary;
import org.jruby.platform.Platform;
Expand All @@ -35,8 +33,6 @@
import org.jruby.util.TypeConverter;

import java.io.File;
import java.io.IOException;
import java.nio.channels.Channel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -2006,7 +2002,7 @@ public int compare(String o1, String o2) {
}

private static String dlnFindExeR(Ruby runtime, String fname, IRubyObject path) {
File exePath = ShellLauncher.findPathExecutable(runtime, fname, path);
File exePath = ShellLauncher.dlnFindExe(runtime, fname, path);
return exePath != null ? exePath.getAbsolutePath() : null;
}

Expand Down

0 comments on commit f5f6d16

Please sign in to comment.