dev-cmd/vendor-gems: fix creation of broken symlinks

When the target symlink already points to an existing directory, the
`#ln_sf` call creates the symlink inside the intended target directory
(which is not what we intend to do here).

Let's fix that.

Closes #16205
This commit is contained in:
Carlo Cabrera 2023-11-13 14:39:47 +08:00
parent d3d51d3448
commit d15ccaf92f
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0
2 changed files with 8 additions and 5 deletions

View File

@ -59,12 +59,16 @@ module Homebrew
mechanize
].each do |gem|
ohai "gem install #{gem}"
safe_system "gem", "install", "mechanize", "--install-dir", "vendor",
safe_system "gem", "install", gem, "--install-dir", "vendor",
"--no-document", "--no-wrappers", "--ignore-dependencies", "--force"
(HOMEBREW_LIBRARY_PATH/"vendor/gems").cd do
if (source = Pathname.glob("#{gem}-*/").first)
FileUtils.ln_sf source, gem
end
source = Pathname.glob("#{gem}-*/").first
next if source.blank?
# We cannot use `#ln_sf` here because that has unintended consequences when
# the symlink we want to create exists and points to an existing directory.
FileUtils.rm_f gem
FileUtils.ln_s source, gem
end
end
end

View File

@ -1 +0,0 @@
mechanize-2.9.1/