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: 9619747cbaec^
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9397aa8cd1f0
Choose a head ref
  • 6 commits
  • 10 files changed
  • 1 contributor

Commits on Jun 17, 2018

  1. Copy the full SHA
    9619747 View commit details
  2. Copy the full SHA
    83e70f9 View commit details
  3. Copy the full SHA
    b2fe554 View commit details
  4. [test] adapt uri:classloader testing

    do not assume isolated run - as other tests pollute class-path
    kares committed Jun 17, 2018
    Copy the full SHA
    b52dcae View commit details
  5. [test] delay requiring 'jruby'

    kares committed Jun 17, 2018
    Copy the full SHA
    a76a022 View commit details
  6. [fix] allow setting jar path as current dir

    refactored - unshared chdir/mkdir dir resolution bits
    resolves GH-1026
    kares committed Jun 17, 2018
    Copy the full SHA
    9397aa8 View commit details
87 changes: 50 additions & 37 deletions core/src/main/java/org/jruby/RubyDir.java
Original file line number Diff line number Diff line change
@@ -172,14 +172,17 @@ private static RubyArray asRubyStringList(Ruby runtime, List<ByteList> dirs) {
}

private static String getCWD(Ruby runtime) {
if (runtime.getCurrentDirectory().startsWith("uri:")) {
return runtime.getCurrentDirectory();
final String cwd = runtime.getCurrentDirectory();
// ^(uri|jar|file|classpath):([^:]*:)?//?.*
if (cwd.startsWith("uri:") || cwd.startsWith("jar:") || cwd.startsWith("file:")) {
// "classpath:" mapped into "uri:classloader:"
return cwd;
}
try {
return new JRubyFile(runtime.getCurrentDirectory()).getCanonicalPath();
try { // NOTE: likely not necessary as we already canonicalized while setting?
return new JRubyFile(cwd).getCanonicalPath();
}
catch (Exception e) {
return runtime.getCurrentDirectory();
catch (IOException e) {
return cwd;
}
}

@@ -378,48 +381,41 @@ public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyOb
RubyString path = args.length == 1 ?
StringSupport.checkEmbeddedNulls(runtime, RubyFile.get_path(context, args[0])) :
getHomeDirectoryPath(context);

String adjustedPath = RubyFile.adjustRootPathOnWindows(runtime, path.asJavaString(), null);
checkDirIsTwoSlashesOnWindows(runtime, adjustedPath);
final String realPath;
final String oldCwd = runtime.getCurrentDirectory();
if (PROTOCOL_PATTERN.matcher(adjustedPath).matches()) {
realPath = adjustedPath;
}
else {
FileResource dir = getDir(runtime, adjustedPath, true);
realPath = dir.canonicalPath();
}

adjustedPath = getExistingDir(runtime, adjustedPath).canonicalPath();

IRubyObject result;
if (block.isGiven()) {
final String oldCwd = runtime.getCurrentDirectory();
// FIXME: Don't allow multiple threads to do this at once
runtime.setCurrentDirectory(realPath);
runtime.setCurrentDirectory(adjustedPath);
try {
result = block.yield(context, path);
} finally {
getDir(runtime, oldCwd, true); // needed in case the block deleted the oldCwd
getExistingDir(runtime, oldCwd); // needed in case the block deleted the oldCwd
runtime.setCurrentDirectory(oldCwd);
}
} else {
runtime.setCurrentDirectory(realPath);
runtime.setCurrentDirectory(adjustedPath);
result = runtime.newFixnum(0);
}

return result;
}

/**
* Changes the root directory (only allowed by super user). Not available
* on all platforms.
* Changes the root directory (only allowed by super user). Not available on all platforms.
*/
@JRubyMethod(name = "chroot", required = 1, meta = true)
public static IRubyObject chroot(IRubyObject recv, IRubyObject path) {
throw recv.getRuntime().newNotImplementedError("chroot not implemented: chroot is non-portable and is not supported.");
}

/**
* Returns an array containing all of the filenames except for "." and ".."
* in the given directory.
* Returns an array containing all of the filenames except for "." and ".." in the given directory.
*/
@JRubyMethod(name = "children", meta = true)
public static RubyArray children(ThreadContext context, IRubyObject recv, IRubyObject arg) {
@@ -445,8 +441,7 @@ private static RubyArray childrenCommon(ThreadContext context, IRubyObject recv,
}

/**
* Deletes the directory specified by <code>path</code>. The directory must
* be empty.
* Deletes the directory specified by <code>path</code>. The directory must be empty.
*/
public static IRubyObject rmdir(IRubyObject recv, IRubyObject path) {
return rmdir19(recv.getRuntime().getCurrentContext(), recv, path);
@@ -573,7 +568,7 @@ public static RubyString getwd(IRubyObject recv) {
*/
@JRubyMethod(name = "home", optional = 1, meta = true)
public static IRubyObject home(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
if (args.length > 0 && !args[0].isNil()) return getHomeDirectoryPath(context, args[0].toString());
if (args.length > 0 && args[0] != context.nil) return getHomeDirectoryPath(context, args[0].toString());

return getHomeDirectoryPath(context);
}
@@ -583,25 +578,31 @@ public static IRubyObject home(ThreadContext context, IRubyObject recv, IRubyObj
* <code>mode</code> parameter is provided only to support existing Ruby
* code, and is ignored.
*/
public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
return mkdir19(recv.getRuntime().getCurrentContext(), recv, args);
}

@JRubyMethod(name = "mkdir", required = 1, optional = 1, meta = true)
public static IRubyObject mkdir19(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
public static IRubyObject mkdir(ThreadContext context, IRubyObject recv, IRubyObject... args) {
Ruby runtime = context.runtime;
RubyString path = StringSupport.checkEmbeddedNulls(runtime, RubyFile.get_path(context, args[0]));
return mkdirCommon(runtime, path.asJavaString(), args);
}

@Deprecated
public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
return mkdir(recv.getRuntime().getCurrentContext(), recv, args);
}

@Deprecated
public static IRubyObject mkdir19(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
return mkdir(context, recv, args);
}

private static IRubyObject mkdirCommon(Ruby runtime, String path, IRubyObject[] args) {
if (path.startsWith("uri:")) {
throw runtime.newErrnoEACCESError(path);
}
File newDir = getDir(runtime, path, false).unwrap(File.class);
if (path.startsWith("uri:")) throw runtime.newErrnoEACCESError(path);

String name = path.replace('\\', '/');
path = dirFromPath(path, runtime);
FileResource res = JRubyFile.createResource(runtime, path);
if (res.isDirectory()) throw runtime.newErrnoEEXISTError(path);

String name = path.replace('\\', '/');
boolean startsWithDriveLetterOnWindows = RubyFile.startsWithDriveLetterOnWindows(name);

// don't attempt to create a dir for drive letters
@@ -614,6 +615,7 @@ private static IRubyObject mkdirCommon(Ruby runtime, String path, IRubyObject[]
if (path.length() == 4 && (path.charAt(0) == '/' && path.charAt(3) == '/')) return RubyFixnum.zero(runtime);
}

File newDir = res.unwrap(File.class);
if (File.separatorChar == '\\') newDir = new File(newDir.getPath());

int mode = args.length == 2 ? ((int) args[1].convertToInteger().getLongValue()) : 0777;
@@ -847,13 +849,13 @@ public IRubyObject fileno(ThreadContext context) {
*
* @param path path for which to return the <code>File</code> object.
* @param mustExist is true the directory must exist. If false it must not.
*/
*/ // split out - no longer used
protected static FileResource getDir(final Ruby runtime, final String path, final boolean mustExist) {
String dir = dirFromPath(path, runtime);

FileResource result = JRubyFile.createResource(runtime, dir);

if (mustExist && !result.exists()) {
if (mustExist && (result == null || !result.exists())) {
throw runtime.newErrnoENOENTError(dir);
}

@@ -870,6 +872,17 @@ protected static FileResource getDir(final Ruby runtime, final String path, fina
return result;
}

private static FileResource getExistingDir(final Ruby runtime, final String path) {
FileResource result = JRubyFile.createResource(runtime, path);
if (result == null || !result.exists()) {
throw runtime.newErrnoENOENTError(path);
}
if (!result.isDirectory()) {
throw runtime.newErrnoENOTDIRError(path);
}
return result;
}

/**
* Similar to getDir, but performs different checks to match rmdir behavior.
* @param runtime
16 changes: 7 additions & 9 deletions test/jruby.index
Original file line number Diff line number Diff line change
@@ -86,32 +86,30 @@ jruby/test_win32
jruby/test_zlib

# these tests are last because they pull in libraries that can affect others
jruby/test_kernel
jruby/test_loading_builtin_libraries
jruby/test_null_channel
jruby/test_irubyobject_java_passing
jruby/test_jruby_object_input_stream
jruby/test_jar_on_load_path
jruby/test_jruby_core_ext
jruby/test_thread_context_frame_dereferences_unreachable_variables
jruby/test_jruby_synchronized
jruby/test_context_classloader
# fails with -j-ea on java :(
# jruby/test_uri_classloader
jruby/test_uri_classloader
jruby/test_rexml_document
jruby/test_openssl_stub
jruby/test_missing_jruby_home
jruby/test_ast_inspector
jruby/test_jarred_gems
jruby/test_kernel
jruby/test_dir_with_plusses
jruby/test_jar_file
jruby/test_jar
# Not sure how to test this, since soft references take too long to collect
#test_thread_service
jruby/test_jruby_synchronized
jruby/test_instantiating_interfaces
jruby/test_openssl
jruby/test_tempfile_cleanup

jruby/test_jruby_core_ext
jruby/test_thread_context_frame_dereferences_unreachable_variables
jruby/test_reified_variables

jruby/compiler/test_jrubyc
jruby/test_load_compiled_ruby
jruby/test_load_compiled_ruby_class_from_classpath
45 changes: 45 additions & 0 deletions test/jruby/test_jar.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'test/unit'

class TestJar < Test::Unit::TestCase

def test_stat_file_in_jar
require 'jruby'
begin
url = JRuby.runtime.jruby_class_loader.get_resource 'org/jruby/Ruby.class'
conn = url.open_connection
real_size = conn.content_length
stat_size = File.stat(url.to_uri.to_s).size

assert_equal(real_size, stat_size)
rescue
conn.close rescue nil
end
end

def test_jar_on_load_path
$LOAD_PATH << "test/jruby/test_jruby_1332.jar!"
require 'test_jruby_1332.rb'
assert($jruby_1332)
end

def test_file_jar_path
jar_file = 'file:' + File.expand_path('gem.jar', File.dirname(__FILE__))
in_jar_file = "#{jar_file}!/specifications"
assert File.directory? in_jar_file
Dir.chdir in_jar_file
assert File.exists?(Dir.pwd), "#{Dir.pwd} does not exist!"
some_path = File.expand_path('SOME')
assert some_path.end_with?('test/jruby/gem.jar!/specifications/SOME')
assert_false File.exists?(some_path), "#{some_path} does exist!"
existing_path = File.expand_path('mygem-1.0.0.gemspec')
assert_true File.exists?(existing_path), "#{existing_path} does not exist!"
assert_true File.file?(existing_path)
end

@@work_dir = Dir.pwd

def teardown
Dir.chdir(@@work_dir)
end

end
17 changes: 0 additions & 17 deletions test/jruby/test_jar_file.rb

This file was deleted.

9 changes: 0 additions & 9 deletions test/jruby/test_jar_on_load_path.rb

This file was deleted.

3 changes: 2 additions & 1 deletion test/jruby/test_objectspace.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
require 'jruby'
require 'test/unit'

class TestObjectSpace < Test::Unit::TestCase

def setup
require 'jruby'
@objectspace = JRuby.objectspace
JRuby.objectspace = true
end
29 changes: 28 additions & 1 deletion test/jruby/test_openssl.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require 'test/unit'
require 'openssl'

class TestOpenssl < Test::Unit::TestCase
class TestOpenSSL < Test::Unit::TestCase

def test_csr_request_extensions
key = OpenSSL::PKey::RSA.new(512)
csr = OpenSSL::X509::Request.new
@@ -25,4 +26,30 @@ def test_csr_request_extensions

assert_equal '/CN=example.com', csr.subject.to_s
end

if OpenSSL::OPENSSL_VERSION_NUMBER > 0x00908000

def test_098_features
sha224_a = "abd37534c7d9a2efb9465de931cd7055ffdb8879563ae98078d6d6d5"
sha256_a = "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb"
sha384_a = "54a59b9f22b0b80880d8427e548b7c23abd873486e1f035dce9cd697e85175033caa88e6d57bc35efae0b5afd3145f31"
sha512_a = "1f40fc92da241694750979ee6cf582f2d5d7d28e18335de05abc54d0560e0f5302860c652bf08d560252aa5e74210546f369fbbbce8c12cfc7957b2652fe9a75"

assert_equal(sha224_a, OpenSSL::Digest::SHA224.hexdigest("a"))
assert_equal(sha256_a, OpenSSL::Digest::SHA256.hexdigest("a"))
assert_equal(sha384_a, OpenSSL::Digest::SHA384.hexdigest("a"))
assert_equal(sha512_a, OpenSSL::Digest::SHA512.hexdigest("a"))

assert_equal(sha224_a, encode16(OpenSSL::Digest::SHA224.digest("a")))
assert_equal(sha256_a, encode16(OpenSSL::Digest::SHA256.digest("a")))
assert_equal(sha384_a, encode16(OpenSSL::Digest::SHA384.digest("a")))
assert_equal(sha512_a, encode16(OpenSSL::Digest::SHA512.digest("a")))
end

def encode16(str)
str.unpack("H*").first
end

end

end
20 changes: 0 additions & 20 deletions test/jruby/test_openssl_stub.rb

This file was deleted.

Loading