Skip to content

Commit

Permalink
Merge pull request #652 from Homebrew/deprecations
Browse files Browse the repository at this point in the history
lib/service: fix deprecations.
  • Loading branch information
MikeMcQuaid authored May 7, 2024
2 parents ec6d0a1 + 6aeccd1 commit b2d75eb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 28 deletions.
14 changes: 6 additions & 8 deletions lib/service/formula_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ def service_file

# Whether the service should be launched at startup
def service_startup?
if service?
@service_startup ||= load_service.requires_root?
return @service_startup
@service_startup ||= if service?
load_service.requires_root?
else
false
end

@service_startup ||= formula.plist_startup.present?
end

# Path to destination service directory. If run as root, it's `boot_path`, else `user_path`.
Expand All @@ -86,12 +85,11 @@ def installed?
formula.any_version_installed?
end

# Returns `true` if the formula implements #plist or the plist file exists.
# Returns `true` if the plist file exists.
def plist?
return false unless installed?
return true if service_file.file?
return true unless formula.plist.nil?
return false unless formula.opt_prefix.exist?
return false unless formula.opt_prefix&.exist?
return true if Keg.for(formula.opt_prefix).plist_installed?

false
Expand Down
2 changes: 1 addition & 1 deletion lib/service/formulae.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def available_services(loaded: nil, skip_root: false)

formulae = Formula.installed
.map { |formula| FormulaWrapper.new(formula) }
.select { |formula| formula.service? || formula.plist? }
.select(&:service?)
.sort_by(&:name)

formulae = formulae.select { |formula| formula.loaded? == loaded } unless loaded.nil?
Expand Down
2 changes: 1 addition & 1 deletion lib/service/services_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def start(targets, service_file = nil, verbose: false)

odie "Formula `#{service.name}` is not installed." unless service.installed?

file ||= if service.service_file.exist? || System.systemctl? || service.formula.plist.blank?
file ||= if service.service_file.exist? || System.systemctl?
nil
elsif service.formula.opt_prefix.exist? && (keg = Keg.for service.formula.opt_prefix) && keg.plist_installed?
service_file = Dir["#{keg}/*#{service.service_file.extname}"].first
Expand Down
18 changes: 0 additions & 18 deletions spec/homebrew/formula_wrapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,6 @@
File.delete(tempfile)
end

it "true if plist" do
allow(service).to receive_messages(installed?: true,
service_file: Pathname.new("/dev/null"),
formula: OpenStruct.new(plist: "a"))
expect(service.plist?).to be(true)
end

it "false if opt_prefix missing" do
allow(service).to receive_messages(installed?: true,
service_file: Pathname.new("/dev/null"),
Expand Down Expand Up @@ -297,17 +290,6 @@

expect(service.service_startup?).to be(true)
end

it "outputs true since there is a startup plist" do
allow(described_class).to receive(:service?).and_return(false)
formula = OpenStruct.new(
plist_startup: true,
)

service = described_class.new(formula)

expect(service.service_startup?).to be(true)
end
end

describe "#to_hash" do
Expand Down

0 comments on commit b2d75eb

Please sign in to comment.