Skip to content

Commit

Permalink
JRUBY-5572: Fix Dir.foreach for jar files
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksieger committed Mar 9, 2011
1 parent 96d14b0 commit 116a639
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/org/jruby/RubyDir.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private final void checkDir() {
}

private void update() {
if (snapshot == null || dir.lastModified() > lastModified) {
if (snapshot == null || dir.exists() && dir.lastModified() > lastModified) {
lastModified = dir.lastModified();
List<String> snapshotList = new ArrayList<String>();
snapshotList.add(".");
Expand Down
14 changes: 14 additions & 0 deletions test/test_dir.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
require 'test/unit'
require 'rbconfig'

Expand Down Expand Up @@ -162,6 +163,19 @@ def test_glob_with_magic_inside_jar_file
end
end

def test_foreach_works_in_jar_file
jar_file = File.expand_path('../jar_with_relative_require1.jar', __FILE__)
jar_path = "file:#{jar_file}!/test"
dir = Dir.new(jar_path)
assert dir.entries.include?('require_relative1.rb'), "#{jar_path} does not contain require_relative1.rb: #{dir.entries.inspect}"
entries = []
dir.each {|d| entries << d}
assert entries.include?('require_relative1.rb'), "#{jar_path} does not contain require_relative1.rb: #{entries.inspect}"
entries = []
Dir.foreach(jar_path) {|d| entries << d}
assert entries.include?('require_relative1.rb'), "#{jar_path} does not contain require_relative1.rb: #{entries.inspect}"
end

def jar_file_with_spaces
require 'test/dir with spaces/test_jar.jar'
require 'inside_jar'
Expand Down

0 comments on commit 116a639

Please sign in to comment.