Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: be44d2d28145
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 64cfd1e20150
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Apr 16, 2018

  1. Restore old PATH logic used by pure-Java processes.

    The newer logic unconditionally searches for the executable in
    PATH and so is not suitable for cases where the executable is a
    relative path from CWD. This caused regressions in
    test/jruby/test_kernel.rb.
    headius committed Apr 16, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    headius Charles Oliver Nutter
    Copy the full SHA
    511c05d View commit details
  2. Clean up imports.

    headius committed Apr 16, 2018
    Copy the full SHA
    64cfd1e View commit details
Showing with 28 additions and 8 deletions.
  1. +27 −3 core/src/main/java/org/jruby/util/ShellLauncher.java
  2. +1 −5 core/src/main/java/org/jruby/util/io/PopenExecutor.java
30 changes: 27 additions & 3 deletions core/src/main/java/org/jruby/util/ShellLauncher.java
Original file line number Diff line number Diff line change
@@ -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()) {
6 changes: 1 addition & 5 deletions core/src/main/java/org/jruby/util/io/PopenExecutor.java
Original file line number Diff line number Diff line change
@@ -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;
@@ -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;
@@ -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;
@@ -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;
}