feat(update): pre-flight permission check with platform-specific hint #25
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/update-permission-check"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Direct answer: no, the original
yt updatedid not check permissions; it would download the binary and then fail at the rename step with a genericPermission deniederror. This PR adds a pre-flight probe so the user sees a clear "use sudo / Administrator" message before any HTTP call.What changed
The flow used to be: resolve URL -> download -> chmod staging -> self-replace. The rename step is what surfaces a write-perm error, so users running
yt updatefrom/usr/local/bin/paid for the download first.New order: resolve URL ->
current_exe()-> probe parent dir for write access -> (if OK) download -> stage -> self-replace.The probe is
OpenOptions::create_new(true).write(true)on a uniquely-named file (.yt-update-probe-<pid>-<nanos>) inside the binary's parent dir, then immediately removed.create_newmeans we're testing actual creation rights, not opening an existing file we happen to own.Error message
Platform-gated via
cfg:permission denied: cannot write to /usr/local/bin. Re-run withsudo yt update, or move the binary to a directory you own (e.g.~/.local/bin/yt).permission denied: cannot write to C:\Program Files\yt. Re-run from an Administrator prompt, or move the binary to a directory you own (e.g.%USERPROFILE%\bin\yt.exe).--dry-runalso runs the probe and errors on permission denied. A planning operation should report the failure mode it'd hit at execution time.Verification
cargo fmt --checkclean.cargo clippy --all-targets -- -D warningsclean.cargo test --all-targets: 186 tests pass (5 new).Coverage on this PR:
Manual verification on Linux:
Test plan
ytto/usr/local/bin/as root and runyt updateas a non-root user: should print the sudo hint and exit non-zero without making an HTTP call.--dry-run: same friendly error.sudo yt update: should succeed.yt updatefrom a non-Administrator command prompt: should print the Administrator hint.