Skip to content

refactor: idiomatic cleanup of EvisionPrecompiled deploy path - #330

Merged
cocoa-xu merged 1 commit into
mainfrom
cx/refactor-precompiled
Jul 19, 2026
Merged

refactor: idiomatic cleanup of EvisionPrecompiled deploy path#330
cocoa-xu merged 1 commit into
mainfrom
cx/refactor-precompiled

Conversation

@cocoa-xu

Copy link
Copy Markdown
Owner

Follow-up to #329. Idiomatic cleanup of the precompiled download → verify → unarchive → deploy flow in Mix.Tasks.Compile.EvisionPrecompiled. Net -74 lines, no functional change to the happy path.

Correctness

verify_checksum/3 returned a 3-tuple {matched?, algo, hash} on success but a 2-tuple {:error, reason} when the file was absent from the checksum map. Both call sites destructured a 3-tuple, so a cached tarball whose basename wasn't listed raised a MatchError instead of surfacing the "run mix evision.fetch" hint. It now returns a consistent :ok | {:error, reason} and owns its diagnostic message; callers case on it.

Idiomatic cleanups

  • nif_installed?/1 collapses the identical .so/.dll path + existence check that was duplicated verbatim between prepare/8 and run/1.
  • deploy_from_dir!/2 drops redundant if File.exists? guards (File.rm_rf! is already a no-op on missing paths) and uses File.cp_r! in place of a with/else/raise block.
  • unarchive!/2 and run/1 replace single-clause with/else with case (per Elixir's anti-patterns guide).
  • prepare/8 derives the tarball name as name <> ".tar.gz" instead of a second 8-arg filename/8 call, and the download block reads as a linear sequence.

Scope

Intentionally left the long positional parameter lists (filename/get_download_url/prepare/run) as-is. Modeling them as a build-spec struct would be gold-plating for a build script, so it was skipped rather than abstracted for its own sake.

Verification

  • Isolated compile under Elixir 1.20.1 is warning-free.
  • The refactored region passes mix format.
  • Every caller of the changed functions lives in mix.exs and uses the new interfaces; the sibling mix evision.fetch task does not touch any of them.

Tighten the precompiled download/verify/unarchive/deploy flow:

- verify_checksum/3 now returns a consistent `:ok | {:error, reason}` and owns
  its diagnostic message, instead of a 3-tuple on success and a 2-tuple on
  error. The old shape raised a MatchError whenever a cached tarball's basename
  was absent from the checksum map, because both callers destructured a 3-tuple.
- cached_tarball_usable?/1 and prepare/8 pattern-match that result via `case`.
- nif_installed?/1 replaces the identical .so/.dll path and existence checks
  that were duplicated between prepare/8 and run/1.
- deploy_from_dir!/2 drops redundant `File.exists?` guards (File.rm_rf! is a
  no-op on missing paths) and uses File.cp_r! instead of a with/else/raise.
- unarchive!/2 and run/1 replace single-clause `with/else` with `case`.

No change to the happy path; the checksum-map-miss case now surfaces the
"run mix evision.fetch" hint instead of crashing.
@cocoa-xu
cocoa-xu merged commit debc07d into main Jul 19, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant