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
support for GEM_HOME_SHARED #596
Closed
Closed
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,10 +28,21 @@ class Gem::Uninstaller | |
attr_reader :bin_dir | ||
|
||
## | ||
# The gem repository the gem will be installed into | ||
# The user path the gems were installed into, | ||
# can be empty - defaults to gem_home | ||
|
||
attr_reader :install_dir | ||
|
||
## | ||
# The gem repository the platform gems were installed into | ||
|
||
attr_reader :gem_home | ||
|
||
## | ||
# The gem repository the shared gems were installed into | ||
|
||
attr_reader :gem_home_shared | ||
|
||
## | ||
# The Gem::Specification for the gem being uninstalled, only set during | ||
# #uninstall_gem | ||
|
@@ -45,7 +56,9 @@ def initialize(gem, options = {}) | |
# TODO document the valid options | ||
@gem = gem | ||
@version = options[:version] || Gem::Requirement.default | ||
@gem_home = File.expand_path(options[:install_dir] || Gem.dir) | ||
@install_dir = options[:install_dir] ? File.expand_path(options[:install_dir]) : nil | ||
@gem_home = File.expand_path(Gem.dir) | ||
@gem_home_shared = Gem.shareddir ? File.expand_path(Gem.shareddir) : "" | ||
@force_executables = options[:executables] | ||
@force_all = options[:all] | ||
@force_ignore = options[:ignore] | ||
|
@@ -68,6 +81,14 @@ def initialize(gem, options = {}) | |
@user_install = options[:user_install] unless options[:install_dir] | ||
end | ||
|
||
def gem_in_uninstallable_path(base_dir) | ||
( | ||
install_dir ? install_dir == base_dir : ( @gem_home == base_dir or @gem_home_shared == base_dir ) | ||
) or ( | ||
@user_install and (Gem.user_dir == base_dir or Gem.shared_user_dir == base_dir) | ||
) | ||
end | ||
|
||
## | ||
# Performs the uninstall of the gem. This removes the spec, the Gem | ||
# directory, and the cached .gem file. | ||
|
@@ -92,8 +113,7 @@ def uninstall | |
end | ||
|
||
list, other_repo_specs = list.partition do |spec| | ||
@gem_home == spec.base_dir or | ||
(@user_install and spec.base_dir == Gem.user_dir) | ||
gem_in_uninstallable_path(spec.base_dir) | ||
end | ||
|
||
if list.empty? then | ||
|
@@ -234,14 +254,7 @@ def remove_all(list) | |
# uninstalled a gem, it is removed from that list. | ||
|
||
def remove(spec) | ||
unless path_ok?(@gem_home, spec) or | ||
(@user_install and path_ok?(Gem.user_dir, spec)) then | ||
e = Gem::GemNotInHomeException.new \ | ||
"Gem is not installed in directory #{@gem_home}" | ||
e.spec = spec | ||
|
||
raise e | ||
end | ||
paths_ok_or_raise(spec) | ||
|
||
raise Gem::FilePermissionError, spec.base_dir unless | ||
File.writable?(spec.base_dir) | ||
|
@@ -274,6 +287,27 @@ def remove(spec) | |
Gem::Specification.remove_spec spec | ||
end | ||
|
||
## | ||
# Confirm spec is one of paths that it can be uninstalled from | ||
|
||
def paths_ok_or_raise(spec) | ||
unless ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please restructure this conditional! |
||
@install_dir ? path_ok?(@install_dir, spec) : ( | ||
path_ok?(@gem_home, spec) or path_ok?(@gem_home_shared, spec) | ||
) | ||
) or ( | ||
@user_install and ( | ||
path_ok?(Gem.user_dir, spec) or path_ok?(Gem.shared_user_dir, spec) | ||
) | ||
) then | ||
e = Gem::GemNotInHomeException.new \ | ||
"Gem is not installed in directory #{@install_dir ? @install_dir : "#{@gem_home_shared} or #{@gem_home}"}" | ||
e.spec = spec | ||
|
||
raise e | ||
end | ||
end | ||
|
||
## | ||
# Is +spec+ in +gem_dir+? | ||
|
||
|
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
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
Oops, something went wrong.
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 was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restructure this method please!