gortex icon indicating copy to clipboard operation
gortex copied to clipboard

Homebrew cask: deprecated postflight can't be ported to postflight_steps (conditional daemon restart)

Open aki-xavier opened this issue 2 months ago • 0 comments

Summary

Homebrew deprecates the postflight cask stanza in favour of postflight_steps:

Warning: Calling `postflight` is deprecated! Use `postflight_steps` instead.

The cask is generated from .github/homebrew/gortex.rb.tmpl and published to the zzet/homebrew-tap. Its postflight block runs a conditional daemon restart on upgrade:

postflight do
  bin = File.join(HOMEBREW_PREFIX, "bin", "gortex")
  next unless File.executable?(bin)
  probe = system_command(bin, args: ["daemon", "status"],
                         must_succeed: false, print_stdout: false)
  next unless probe.success?
  system_command(bin, args: ["daemon", "restart"], must_succeed: false)
end

Why the guard matters (it is load-bearing)

On brew upgrade, the old daemon is still live on the previous binary's image and still owns the store's on-disk lock, so the cask bounces it onto the new binary so any store migration runs alone. But on a fresh install or CI, no daemon runs — and the guard (next unless probe.success?) intentionally skips the restart instead of starting a daemon nobody asked for.

I verified the gortex CLI really would start one: runDaemonRestart (cmd/gortex/daemon.go) calls runDaemonStop (idempotent when not running) and then unconditionally runDaemonStart, which starts a daemon. So without the guard, brew install/CI machines would spawn a gortex daemon.

The problem: postflight_steps can't express the guard

postflight_steps is a declarative install-steps DSL whose guards are static — on_macos, on_linux, if_path_exists, unless_exists — evaluated against the filesystem/OS. There is no way to gate a step on a preceding command's exit status (the matcher only handles if_exists/unless_exists/on). So "probe daemon status, and only run daemon restart if it succeeded" is not expressible.

Every faithful port differs from today's behaviour:

  • Always run daemon restart (with must_succeed: false): spawns a daemon on fresh install/CI — the exact thing the guard prevents.
  • Drop the restart-on-upgrade entirely: loses the lock/migration coordination on upgrade.

Proposal (needs a decision)

The clean, behaviour-preserving fix is to make gortex daemon restart a no-op when no daemon is running, then simplify the template to postflight_steps:

postflight_steps do
  if_path_exists "#{HOMEBREW_PREFIX}/bin/gortex" do
    run "gortex", args: ["daemon", "restart"], must_succeed: false
  end
end

That moves the "don't start a daemon nobody asked for" logic into the CLI (short-circuit runDaemonRestart/runDaemonStart when nothing is running), which is arguably the more correct semantics for restart anyway. It also removes the postflight deprecation warning for good.

Tradeoff to decide: a user manually running gortex daemon restart when no daemon is running would no longer start one. If restart should mean "start-or-restart", then the alternative is to keep postflight and accept the deprecation (risk: Homebrew eventually removes postflight), or drop the upgrade bounce.

Files involved

  • .github/homebrew/gortex.rb.tmpl — renders the cask (this is what render-cask.sh/validate-cask.sh emit).
  • cmd/gortex/daemon.go — runDaemonRestart / runDaemonStart / runDaemonStop.

Happy to implement the chosen option as a PR.

aki-xavier avatar Sep 09 '26 00:09 aki-xavier