New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build_extensions conditions check fix #912
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There is a logical flaw if gem's extension has or may be (re)built. It can start compilation even without write permissions to the build/target directory: ```ruby return if !File.writable?(base_dir) && !File.exist?(File.join(base_dir, 'extensions')) # Stop build attempt when `base_dir` is not writable **and** `base_dir/extensions` not yet exists ``` In other words condition will pass if `base_dir/extensions` is missing even when directory is not writable. It may result in following exception for some gems with C/C++ extensions like nokogiri: ``` /usr/lib64/ruby/2.1.0/fileutils.rb:250:in `mkdir': Permission denied @ dir_s_mkdir - /usr/lib64/ruby/gems/2.1.0/extensions/x86_64-linux (Errno::EACCES) from /usr/lib64/ruby/2.1.0/fileutils.rb:250:in `fu_mkdir' from /usr/lib64/ruby/2.1.0/fileutils.rb:224:in `block (2 levels) in mkdir_p' from /usr/lib64/ruby/2.1.0/fileutils.rb:222:in `reverse_each' from /usr/lib64/ruby/2.1.0/fileutils.rb:222:in `block in mkdir_p' from /usr/lib64/ruby/2.1.0/fileutils.rb:208:in `each' from /usr/lib64/ruby/2.1.0/fileutils.rb:208:in `mkdir_p' from /usr/lib64/ruby/2.1.0/rubygems/ext/builder.rb:210:in `write_gem_make_out' from /usr/lib64/ruby/2.1.0/rubygems/ext/builder.rb:132:in `build_error' from /usr/lib64/ruby/2.1.0/rubygems/ext/builder.rb:171:in `rescue in build_extension' from /usr/lib64/ruby/2.1.0/rubygems/ext/builder.rb:156:in `build_extension' from /usr/lib64/ruby/2.1.0/rubygems/ext/builder.rb:198:in `block in build_extensions' from /usr/lib64/ruby/2.1.0/rubygems/ext/builder.rb:195:in `each' from /usr/lib64/ruby/2.1.0/rubygems/ext/builder.rb:195:in `build_extensions' from /usr/lib64/ruby/2.1.0/rubygems/specification.rb:1436:in `block in build_extensions' from /usr/lib64/ruby/2.1.0/rubygems/user_interaction.rb:45:in `use_ui' from /usr/lib64/ruby/2.1.0/rubygems/specification.rb:1434:in `build_extensions' from /usr/lib64/ruby/2.1.0/rubygems/stub_specification.rb:60:in `build_extensions' from /usr/lib64/ruby/2.1.0/rubygems/basic_specification.rb:56:in `contains_requirable_file?' from /usr/lib64/ruby/2.1.0/rubygems/specification.rb:925:in `block in find_inactive_by_path' ```
This seems OK, can you update the test? |
Was looking into this to write a test and found the diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index fedd52f..c4d7f6c 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -1440,8 +1440,10 @@ class Gem::Specification < Gem::BasicSpecification
return if extensions.empty?
return if installed_by_version < Gem::Version.new('2.2.0.preview.2')
return if File.exist? gem_build_complete_path
- return if !File.writable?(base_dir) ||
- !File.exist?(File.join(base_dir, 'extensions'))
+ return if !File.exist?(base_dir)
+ return if !File.writable?(base_dir)
+ return if !File.exist?(File.join(base_dir, 'extensions'))
+ return if !File.writable?(File.join(base_dir, 'extensions'))
begin
# We need to require things in $LOAD_PATH without looking for the Each return can be independent, but I'm wondering if we only need the last 2 checks for |
zzak
pushed a commit
to zzak/rubygems
that referenced
this pull request
May 18, 2014
…o separate returns. If `build_dir/extensions` is not writable, we shouldn't try to compile the extension.
zzak
pushed a commit
to zzak/rubygems
that referenced
this pull request
May 18, 2014
Merged manually via 4411bca Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There is a logical flaw if gem's extension has or may be (re)built.
It can start compilation even without write permissions to the build/target directory:
In other words condition will pass if
base_dir/extensions
is missing even when directory is not writable. It may result in following exception for some gems with C/C++ extensions like nokogiri:Proposed simple fix just narrows this flaw so compilation won't start if permissions lacking or if directory permissions are ok but extensions are not yet built.