Skip to content

Commit

Permalink
Showing 61 changed files with 1,131 additions and 564 deletions.
8 changes: 0 additions & 8 deletions core/src/main/java/org/jruby/RubyThread.java
Original file line number Diff line number Diff line change
@@ -1768,14 +1768,6 @@ public boolean select(Channel channel, OpenFile fptr, int ops, long timeout) {
// so that we can ensure one failing does not affect the others
// running.

// clean up the key in the selector
try {
if (key != null) key.cancel();
if (currentSelector != null) currentSelector.selectNow();
} catch (Exception e) {
// ignore
}

// shut down and null out the selector
try {
if (currentSelector != null) {
21 changes: 1 addition & 20 deletions core/src/main/java/org/jruby/util/io/SelectExecutor.java
Original file line number Diff line number Diff line change
@@ -50,17 +50,12 @@ IRubyObject selectCall(ThreadContext context) throws IOException {
}

IRubyObject selectEnd(ThreadContext context) throws IOException {
fdTerm(readKeyList);
fdTerm(writeKeyList);
fdTerm(errorKeyList);

if (selectors != null) {
for (int i = 0; i < selectors.size(); i++) {
Selector selector = selectors.get(i);
// if it is a JDK selector, cache it
if (selector.provider() == SelectorProvider.provider()) {
// clear cancelled keys (with selectNow) and return to pool
selector.selectNow();
// return to pool
context.runtime.getSelectorPool().put(selector);
} else {
selector.close();
@@ -277,20 +272,6 @@ private boolean fdIsSet(List<SelectionKey> fds, ChannelFD fd, int operations) {
return false;
}

private void fdTerm(List<SelectionKey> keys) {
if (keys == null) return;
for (int i = 0; i < keys.size(); i++) {
SelectionKey key = keys.get(i);
killKey(key);
}
}

private void killKey(SelectionKey key) {
try {
if (key.isValid()) key.cancel();
} catch (Exception e) {}
}

private SelectionKey trySelectRead(ThreadContext context, ChannelFD fd) throws IOException {
if (fd.chSelect != null) {
return registerSelect(getSelector(context, fd.chSelect), fd, fd.chSelect, READ_ACCEPT_OPS);
15 changes: 13 additions & 2 deletions core/src/main/java/org/jruby/util/io/SelectorPool.java
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@
package org.jruby.util.io;

import java.io.IOException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.util.ArrayList;
import java.util.List;
@@ -38,6 +39,7 @@
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Iterator;

/**
* This is a simple implementation of a hard-referenced java.nio.channels.Selector
@@ -82,7 +84,16 @@ public synchronized Selector get(SelectorProvider provider) throws IOException{
*
* @param selector the selector to put back
*/
public synchronized void put(Selector selector) {
public void put(Selector selector) {
Iterator<SelectionKey> key_iterator = selector.keys().iterator();
while(key_iterator.hasNext()) key_iterator.next().cancel();

try {
selector.selectNow();
} catch (Exception e) {
//ignore
}

returnToPool(selector);
}

@@ -130,7 +141,7 @@ private Selector retrieveFromPool(SelectorProvider provider) throws IOException
return selector;
}

private void returnToPool(Selector selector) {
private synchronized void returnToPool(Selector selector) {
openSelectors.remove(selector);
if (selector.isOpen()) {
SelectorProvider provider = selector.provider();
44 changes: 42 additions & 2 deletions lib/ruby/stdlib/rubygems.rb
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
require 'thread'

module Gem
VERSION = '2.6.4'
VERSION = '2.6.6'
end

# Must be first since it unloads the prelude from 1.9.2
@@ -154,6 +154,26 @@ module Gem
specifications/default
]

##
# Exception classes used in a Gem.read_binary +rescue+ statement. Not all of
# these are defined in Ruby 1.8.7, hence the need for this convoluted setup.

READ_BINARY_ERRORS = begin
read_binary_errors = [Errno::EACCES]
read_binary_errors << Errno::ENOTSUP if Errno.const_defined?(:ENOTSUP)
read_binary_errors
end.freeze

##
# Exception classes used in Gem.write_binary +rescue+ statement. Not all of
# these are defined in Ruby 1.8.7.

WRITE_BINARY_ERRORS = begin
write_binary_errors = []
write_binary_errors << Errno::ENOTSUP if Errno.const_defined?(:ENOTSUP)
write_binary_errors
end.freeze

@@win_platform = nil

@configuration = nil
@@ -829,7 +849,7 @@ def self.read_binary(path)
f.flock(File::LOCK_EX)
f.read
end
rescue Errno::EACCES
rescue *READ_BINARY_ERRORS
open path, 'rb' do |f|
f.read
end
@@ -843,6 +863,26 @@ def self.read_binary(path)
end
end

##
# Safely write a file in binary mode on all platforms.
def self.write_binary(path, data)
open(path, 'wb') do |io|
begin
io.flock(File::LOCK_EX)
rescue *WRITE_BINARY_ERRORS
end
io.write data
end
rescue Errno::ENOLCK # NFS
if Thread.main != Thread.current
raise
else
open(path, 'wb') do |io|
io.write data
end
end
end

##
# The path to the running Ruby interpreter.

2 changes: 1 addition & 1 deletion lib/ruby/stdlib/rubygems/commands/update_command.rb
Original file line number Diff line number Diff line change
@@ -241,7 +241,7 @@ def update_rubygems
update_gem 'rubygems-update', version

installed_gems = Gem::Specification.find_all_by_name 'rubygems-update', requirement
version = installed_gems.last.version
version = installed_gems.first.version

install_rubygems version
end
2 changes: 1 addition & 1 deletion lib/ruby/stdlib/rubygems/config_file.rb
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ class Gem::ConfigFile
# For Ruby implementers to set configuration defaults. Set in
# rubygems/defaults/#{RUBY_ENGINE}.rb

PLATFORM_DEFAULTS = {}
PLATFORM_DEFAULTS = Gem.platform_defaults

# :stopdoc:

18 changes: 18 additions & 0 deletions lib/ruby/stdlib/rubygems/defaults.rb
Original file line number Diff line number Diff line change
@@ -175,4 +175,22 @@ def self.vendor_dir # :nodoc:
RbConfig::CONFIG['ruby_version']
end

##
# Default options for gem commands.
#
# The options here should be structured as an array of string "gem"
# command names as keys and a string of the default options as values.
#
# Example:
#
# def self.platform_defaults
# {
# 'install' => '--no-rdoc --no-ri --env-shebang',
# 'update' => '--no-rdoc --no-ri --env-shebang'
# }
# end

def self.platform_defaults
{}
end
end
11 changes: 7 additions & 4 deletions lib/ruby/stdlib/rubygems/defaults/jruby.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
require 'rubygems/config_file'
require 'rbconfig'
require 'jruby/util'

module Gem

ConfigFile::PLATFORM_DEFAULTS['install'] = '--no-rdoc --no-ri --env-shebang'
ConfigFile::PLATFORM_DEFAULTS['update'] = '--no-rdoc --no-ri --env-shebang'

class << self
alias_method :original_ruby, :ruby
def ruby
@@ -22,6 +18,13 @@ def jarred_path?(p)
end
end

def self.platform_defaults
return {
'install' => '--no-rdoc --no-ri --env-shebang',
'update' => '--no-rdoc --no-ri --env-shebang'
}
end

# Default home directory path to be used if an alternate value is not
# specified in the environment.
#
1 change: 1 addition & 0 deletions lib/ruby/stdlib/rubygems/installer.rb
Original file line number Diff line number Diff line change
@@ -284,6 +284,7 @@ def install

# Completely remove any previous gem files
FileUtils.rm_rf gem_dir
FileUtils.rm_rf spec.extension_dir

FileUtils.mkdir_p gem_dir

4 changes: 3 additions & 1 deletion lib/ruby/stdlib/rubygems/package.rb
Original file line number Diff line number Diff line change
@@ -211,7 +211,9 @@ def add_files tar # :nodoc:
stat = File.lstat file

if stat.symlink?
tar.add_symlink file, File.readlink(file), stat.mode
relative_dir = File.dirname(file).sub("#{Dir.pwd}/", '')
target_path = File.join(relative_dir, File.readlink(file))
tar.add_symlink file, target_path, stat.mode
end

next unless stat.file?
26 changes: 10 additions & 16 deletions lib/ruby/stdlib/rubygems/package/tar_writer.rb
Original file line number Diff line number Diff line change
@@ -310,27 +310,21 @@ def mkdir(name, mode)
# Splits +name+ into a name and prefix that can fit in the TarHeader

def split_name(name) # :nodoc:
if name.bytesize > 256
if name.bytesize > 256 then
raise Gem::Package::TooLongFileName.new("File \"#{name}\" has a too long path (should be 256 or less)")
end

if name.bytesize <= 100 then
prefix = ""
else
parts = name.split(/\//)
newname = parts.pop
nxt = ""

loop do
nxt = parts.pop
break if newname.bytesize + 1 + nxt.bytesize > 100
newname = nxt + "/" + newname
prefix = ''
if name.bytesize > 100 then
parts = name.split('/', -1) # parts are never empty here
name = parts.pop # initially empty for names with a trailing slash ("foo/.../bar/")
prefix = parts.join('/') # if empty, then it's impossible to split (parts is empty too)
while !parts.empty? && (prefix.bytesize > 155 || name.empty?)
name = parts.pop + '/' + name
prefix = parts.join('/')
end

prefix = (parts + [nxt]).join "/"
name = newname

if name.bytesize > 100
if name.bytesize > 100 or prefix.empty? then
raise Gem::Package::TooLongFileName.new("File \"#{prefix}/#{name}\" has a too long name (should be 100 or less)")
end

16 changes: 1 addition & 15 deletions lib/ruby/stdlib/rubygems/remote_fetcher.rb
Original file line number Diff line number Diff line change
@@ -328,20 +328,7 @@ def cache_update_path uri, path = nil, update = true
end

if update and path
begin
open(path, 'wb') do |io|
io.flock(File::LOCK_EX)
io.write data
end
rescue Errno::ENOLCK # NFS
if Thread.main != Thread.current
raise
else
open(path, 'wb') do |io|
io.write data
end
end
end
Gem.write_binary(path, data)
end

data
@@ -427,4 +414,3 @@ def pools_for proxy
end
end
end

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true
module Gem::Resolver::Molinillo
# @!visibility private
module Delegates
# Delegates all {Gem::Resolver::Molinillo::ResolutionState} methods to a `#state` property.
module ResolutionState
# (see Gem::Resolver::Molinillo::ResolutionState#name)
def name
current_state = state || Gem::Resolver::Molinillo::ResolutionState.empty
current_state.name
end

# (see Gem::Resolver::Molinillo::ResolutionState#requirements)
def requirements
current_state = state || Gem::Resolver::Molinillo::ResolutionState.empty
current_state.requirements
end

# (see Gem::Resolver::Molinillo::ResolutionState#activated)
def activated
current_state = state || Gem::Resolver::Molinillo::ResolutionState.empty
current_state.activated
end

# (see Gem::Resolver::Molinillo::ResolutionState#requirement)
def requirement
current_state = state || Gem::Resolver::Molinillo::ResolutionState.empty
current_state.requirement
end

# (see Gem::Resolver::Molinillo::ResolutionState#possibilities)
def possibilities
current_state = state || Gem::Resolver::Molinillo::ResolutionState.empty
current_state.possibilities
end

# (see Gem::Resolver::Molinillo::ResolutionState#depth)
def depth
current_state = state || Gem::Resolver::Molinillo::ResolutionState.empty
current_state.depth
end

# (see Gem::Resolver::Molinillo::ResolutionState#conflicts)
def conflicts
current_state = state || Gem::Resolver::Molinillo::ResolutionState.empty
current_state.conflicts
end
end
end
end
Loading

0 comments on commit fafbe32

Please sign in to comment.