Skip to content

Commit

Permalink
Merge pull request #16199 from MikeMcQuaid/utils_gems_ruby3_tweaks
Browse files Browse the repository at this point in the history
utils/gems: improve behaviour (particularly with Ruby 3)
  • Loading branch information
MikeMcQuaid committed Nov 9, 2023
2 parents fd6d412 + e9aae0f commit a808e30
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Library/Homebrew/utils/gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,25 @@ def user_gem_groups
end

def write_user_gem_groups(groups)
return if @user_gem_groups == groups && GEM_GROUPS_FILE.exist?

# Write the file atomically, in case we're working parallel
require "tempfile"
tmpfile = Tempfile.new([GEM_GROUPS_FILE.basename.to_s, "~"], GEM_GROUPS_FILE.dirname)
path = tmpfile.path
return if path.nil?

require "fileutils"
begin
FileUtils.chmod("+r", path)
tmpfile.write(groups.join("\n"))
tmpfile.close
File.rename(tmpfile.path.to_s, GEM_GROUPS_FILE)
File.rename(path, GEM_GROUPS_FILE)
ensure
tmpfile.unlink
end

@user_gem_groups = groups
end

def forget_user_gem_groups!
Expand All @@ -212,6 +221,7 @@ def forget_user_gem_groups!
require "settings"
Homebrew::Settings.delete(:gemgroups)
end
@user_gem_groups = []
end

def user_vendor_version
Expand Down

0 comments on commit a808e30

Please sign in to comment.