Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,8 @@ dir_each_entry(VALUE dir, VALUE (*each)(VALUE, VALUE, struct dir_entry_args *),
.dp = dp,
};
(*each)(arg, path, &each_args);
/* the block may have closed dir */
if (!dirp->dir) dir_closed();
}
return dir;
}
Expand Down
11 changes: 11 additions & 0 deletions test/ruby/test_dir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,17 @@ def test_close
assert_raise(IOError) { d.read }
end

def test_each_with_close
d = Dir.open(@root)
assert_raise(IOError) { d.each { d.close } }

d = Dir.open(@root)
assert_raise(IOError) { d.each_child { d.close } }

d = Dir.open(@root)
assert_raise(IOError) { d.scan { |*| d.close } }
end

def test_glob
assert_equal((%w(.) + ("a".."z").to_a).map{|f| File.join(@root, f) },
Dir.glob(File.join(@root, "*"), File::FNM_DOTMATCH))
Expand Down