Skip to content

Commit 52a7b67

Browse files
committed
Revert "Revert "services: add loaded_file data""
This reverts commit 76901b1.
1 parent 334bf23 commit 52a7b67

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Library/Homebrew/services/formula_wrapper.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ def exit_code
188188
Regexp.last_match(1).to_i if status_output =~ exit_code_regex(status_type)
189189
end
190190

191+
def loaded_file
192+
status_output, _, status_type = status_output_success_type
193+
Regexp.last_match(1) if status_output =~ loaded_file_regex(status_type)
194+
end
195+
191196
sig { returns(T::Hash[Symbol, T.anything]) }
192197
def to_hash
193198
hash = {
@@ -202,6 +207,7 @@ def to_hash
202207
status: status_symbol,
203208
file: service_file_present? ? dest : service_file,
204209
registered: service_file_present?,
210+
loaded_file:,
205211
}
206212

207213
return hash unless service?
@@ -302,6 +308,15 @@ def pid_regex(status_type)
302308
@pid_regex.fetch(status_type)
303309
end
304310

311+
def loaded_file_regex(status_type)
312+
@loaded_file_regex ||= {
313+
launchctl_list: //, # not available
314+
launchctl_print: /path = (.*)/,
315+
systemctl: /Loaded: .*? \((.*);/,
316+
}
317+
@loaded_file_regex.fetch(status_type)
318+
end
319+
305320
sig { returns(T::Boolean) }
306321
def boot_path_service_file_present?
307322
boot_path = System.boot_path

Library/Homebrew/test/services/formula_wrapper_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@
369369
exit_code: nil,
370370
file: Pathname.new("/usr/local/opt/mysql/homebrew.mysql.plist"),
371371
loaded: false,
372+
loaded_file: nil,
372373
name: "mysql",
373374
pid: nil,
374375
registered: false,
@@ -390,6 +391,7 @@
390391
exit_code: nil,
391392
file: Pathname.new("/tmp_home/Library/LaunchAgents/homebrew.mysql.plist"),
392393
loaded: false,
394+
loaded_file: nil,
393395
name: "mysql",
394396
pid: nil,
395397
registered: true,
@@ -416,6 +418,7 @@
416418
file: Pathname.new("/tmp_home/Library/LaunchAgents/homebrew.mysql.plist"),
417419
interval: nil,
418420
loaded: false,
421+
loaded_file: nil,
419422
log_path: nil,
420423
name: "mysql",
421424
pid: nil,

0 commit comments

Comments
 (0)