Skip to content

feat: add 'uteke update' self-update command (#581) - #601

Closed
ajianaz wants to merge 1 commit into
developfrom
feat/uteke-update-command
Closed

ajianaz wants to merge 1 commit into
developfrom
feat/uteke-update-command

Conversation

@ajianaz

@ajianaz ajianaz commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Closes #581

Summary

Add uteke update CLI subcommand that checks for the latest release, compares against the installed version, prompts for confirmation, and downloads + atomically replaces the binary in-place.

User Flow

$ uteke update
[INFO] Current version: 0.6.7
[INFO] Latest version:  0.7.0
[INFO] Release notes:  https://github.com/codecoradev/uteke/releases/tag/v0.7.0
? Update to v0.7.0? [y/N] y
[INFO] Downloading uteke-x86_64-unknown-linux-gnu-v0.7.0.tar.gz ...
[INFO] Verifying checksum ...
[INFO] Checksum verified: abc123...
[INFO] Extracting ...
[INFO] Verified new binary: 0.7.0
[INFO] Update complete. (0.6.7 → 0.7.0)

Implementation

Files changed

  • crates/uteke-cli/Cargo.toml — added sha2, flate2, tar deps
  • crates/uteke-cli/src/cli.rs — added Update { yes } variant to Commands enum
  • crates/uteke-cli/src/commands/mod.rs — module declaration + dispatch
  • crates/uteke-cli/src/commands/update.rs — new file (~200 lines)

Key design decisions

  • Reuses install.sh logic — same OS/arch detection, download URL pattern, checksum verification
  • Primary: 302 redirect — no GitHub API call, no rate limit concerns
  • Fallback: GitHub API — with User-Agent header
  • SHA256 checksum — verifies against checksums-sha256.txt release asset
  • CWE-22 protection — rejects archive entries with absolute paths or .. components
  • Atomic rename — writes to .new temp file first, then fs::rename (atomic on POSIX)
  • Binary verification — runs --version on new binary before replacing
  • --yes / -y — skip confirmation (useful for CI/cron)
  • No clippy warnings — verified locally (full build requires libssl-dev on CI)

Dependencies added

Crate Reason
sha2 SHA256 checksum verification
flate2 gzip decompression (tar.gz archives)
tar tar archive extraction

Check for latest release on GitHub, compare against installed version,
prompt for confirmation, download with checksum verification, and
atomically replace the running binary.

Features:
- Detects current binary path automatically
- OS/arch detection (linux/darwin, x86_64/aarch64)
- Primary: parse GitHub 302 redirect (no API rate limit)
- Fallback: GitHub REST API
- SHA256 checksum verification from release assets
- Archive path traversal protection (CWE-22)
- Atomic rename replace (safe on POSIX)
- New binary verification before swap
- --yes flag for non-interactive / CI use
- Already-up-to-date detection (skip download)
- Missing dev headers warning for cargo-installed binaries

Closes #581
"https://github.com/{REPO}/releases/download/{latest_version}/checksums-sha256.txt"
);

println!("[INFO] Verifying checksum ...");
println!("[WARN] Checksum for {archive_name} not found — skipping verification");
}
} else {
println!("[WARN] Failed to download checksums — skipping verification");
return Err(format!(
"New binary failed to run: {}",
String::from_utf8_lossy(&output.stderr)
)
"x86_64" => "x86_64".to_string(),
"aarch64" => "aarch64".to_string(),
arch => arch.to_string(),
}
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (4)

  • crates/uteke-cli/src/commands/update.rs:175 — The update step does fs::rename(&temp_new, &current_exe)?; after verifying the new binary. Replacing the currently running executable this way works on many POSIX systems, but it commonly fails on Windows because the running .exe is locked by the process. The new Update command is exposed unconditionally in cli.rs, while detect_os()/get_target() do not reject Windows early, so Windows users can reach a path that downloads an archive and then fails during replacement.
  • crates/uteke-cli/src/commands/update.rs:209 — In get_latest_version(), the code comments say it parses the 302 redirect from https://github.com/{REPO}/releases/latest, but the reqwest::blocking::Client::new() uses the default redirect policy, which follows redirects automatically. After redirects are followed, the final response usually no longer contains the intermediate location header, so resp.headers().get("location") will often be empty and the code falls back to the API path every time. That changes behavior from the intended 'no API call, no rate limit' path and can make update checks fail under GitHub API rate limiting.
  • crates/uteke-cli/src/commands/update.rs:94 — The checksum step is optional here: if checksums-sha256.txt cannot be fetched or does not contain the archive entry, the code prints a warning and continues to extract and install the downloaded binary. Because this command replaces the executable itself, silently accepting an unverified payload weakens the trust model and allows installation to proceed without integrity validation whenever the checksum fetch fails.
  • crates/uteke-cli/src/commands/update.rs:113 — The tar safety check converts each entry path to a string and rejects only starts_with('/') or contains(".."). This is not a reliable traversal test because it operates on the raw string form instead of path components. A path like dir/../uteke contains .. but is actually normalizable inside the temp dir, while crafted paths using platform-specific separators or unusual component encodings may bypass simple substring checks. Since archive.unpack(&temp_dir)? is later called on the full archive, this check should be component-aware.

Review powered by cora-cli · BYOK · MIT

@ajianaz

ajianaz commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

Closing in favor of fix PR with corrected naming (Update → Upgrade) and all compilation errors resolved.

@ajianaz ajianaz closed this Jul 7, 2026
@ajianaz
ajianaz deleted the feat/uteke-update-command branch July 9, 2026 14:27
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.

feat: command — self-update with confirmation

2 participants