Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Auto merge of #5564 - bundler:seg-load-gempspec-chdir, r=indirect
Browse files Browse the repository at this point in the history
[Bundler] Avoid chdir when loading a yaml gemspec
  • Loading branch information
bundlerbot committed Apr 7, 2017
2 parents 456b34b + 72af8a4 commit 7358d85
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
22 changes: 11 additions & 11 deletions lib/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,20 +413,20 @@ def load_gemspec(file, validate = false)

def load_gemspec_uncached(file, validate = false)
path = Pathname.new(file)
# Eval the gemspec from its parent directory, because some gemspecs
# depend on "./" relative paths.
SharedHelpers.chdir(path.dirname.to_s) do
contents = path.read
spec = if contents[0..2] == "---" # YAML header
eval_yaml_gemspec(path, contents)
else
contents = path.read
spec = if contents.start_with?("---") # YAML header
eval_yaml_gemspec(path, contents)
else
# Eval the gemspec from its parent directory, because some gemspecs
# depend on "./" relative paths.
SharedHelpers.chdir(path.dirname.to_s) do
eval_gemspec(path, contents)
end
return unless spec
spec.loaded_from = path.expand_path.to_s
Bundler.rubygems.validate(spec) if validate
spec
end
return unless spec
spec.loaded_from = path.expand_path.to_s
Bundler.rubygems.validate(spec) if validate
spec
end

def clear_gemspec_cache
Expand Down
13 changes: 8 additions & 5 deletions lib/bundler/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -746,11 +746,13 @@ def converge_locked_specs

# Don't add a spec to the list if its source is expired. For example,
# if you change a Git gem to Rubygems.
next if s.source.nil? || @unlock[:sources].include?(s.source.name)
next if s.source.nil?
next if @unlock[:sources].include?(s.source.name)

# XXX This is a backwards-compatibility fix to preserve the ability to
# unlock a single gem by passing its name via `--source`. See issue #3759
next if s.source.nil? || @unlock[:sources].include?(s.name)
# TODO: delete in Bundler 2
next if @unlock[:sources].include?(s.name)

# If the spec is from a path source and it doesn't exist anymore
# then we unlock it.
Expand All @@ -774,14 +776,15 @@ def converge_locked_specs

resolve = SpecSet.new(converged)
resolve = resolve.for(expand_dependencies(deps, true), @unlock[:gems])
diff = @locked_specs.to_a - resolve.to_a
diff = nil

# Now, we unlock any sources that do not have anymore gems pinned to it
sources.all_sources.each do |source|
next unless source.respond_to?(:unlock!)

unless resolve.any? {|s| s.source == source }
source.unlock! if !diff.empty? && diff.any? {|s| s.source == source }
diff ||= @locked_specs.to_a - resolve.to_a
source.unlock! if diff.any? {|s| s.source == source }
end
end

Expand All @@ -796,7 +799,7 @@ def in_locked_deps?(dep, locked_dep)
end

def satisfies_locked_spec?(dep)
@locked_specs.any? {|s| s.satisfies?(dep) && (!dep.source || s.source.include?(dep.source)) }
@locked_specs[dep].any? {|s| s.satisfies?(dep) && (!dep.source || s.source.include?(dep.source)) }
end

# This list of dependencies is only used in #resolve, so it's OK to add
Expand Down

0 comments on commit 7358d85

Please sign in to comment.