Repository navigation
Get past a stale root-owned backup in the macOS self-update swap - #5827
Merged
Gabriel Dufresne (GabrielDuf) merged 2 commits intoNov 24, 2026
Merged
Conversation
A Jamf .pkg install leaves UniGetUI.app owned by root. Updating it with an updater older than 2026.3.3, run by an admin user, renamed it to UniGetUI.app.old, moved the new user-owned version in, and could not delete the root-owned .old. From then on every swap failed: rm -rf of the .old failed silently, and mv then tried to move the app into that folder and got Permission denied, so the app relaunched on the same version. - Both the macOS and Linux swap scripts now set the old version aside under a unique name when the .old cannot be deleted, and the macOS one writes mv's error into the update log, as the Linux one already did. It also relaunches the old version from wherever it was left if the rollback fails. - The update loop starts before the main window checks the previous attempt, and its first reset wiped that attempt's log, so the "could not replace" banner never showed. PreviousUpdateAttempt captures that log once, before anything overwrites it, and keeps a copy for View log. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- macOS: when the rollback fails, the old version is left under a .old name, which LaunchServices refuses to open, so open -na relaunched nothing. The script now starts that backup's executable directly. - Both scripts: if mktemp or rmdir fails while picking a backup name, the swap no longer moves the app to an empty or existing path. It keeps the installed version and logs why. - PreviousUpdateAttempt now returns its snapshot even when the copy cannot be written, does not remember a failed read, and says whether the copy was written, so View log never opens an older copy. - The stale-backup tests rely on a read-only folder, so they are skipped when running as root. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The macOS update and rollback paths have only stubbed sandbox coverage, leaving packaged-app recovery around a root-owned .old bundle, resource loading, and LaunchServices relaunch unverified.
No open issues 🎉
What changed in this PR
This PR strengthens UniGetUI’s self-update recovery, extending #5578’s macOS fixes to handle undeletable stale backups and preserve failure details across startup.
Changes:
- Use unique backup names when stale
.oldfolders block macOS or Linux update swaps. - Improve macOS swap-error logging and relaunch the backup executable if rollback fails.
- Preserve the previous update log for startup warnings and View log, with regression tests for snapshot and swap behavior.
| File | Description |
|---|---|
src/UniGetUI.Core.Tools/PreviousUpdateAttempt.cs |
Captures and copies the previous update log before replacement. |
src/UniGetUI.Core.Tools/MacUpdateTarget.cs |
Handles stale backups, records move errors, and improves rollback relaunch. |
src/UniGetUI.Core.Tools/LinuxUpdateTarget.cs |
Adds unique-backup fallback for undeletable stale folders. |
src/UniGetUI.Core.Tools.Tests/PreviousUpdateAttemptTests.cs |
Tests snapshot retention, absent logs, and copy-write failures. |
src/UniGetUI.Core.Tools.Tests/PlatformFacts.cs |
Adds non-root guards for permission-dependent tests. |
src/UniGetUI.Core.Tools.Tests/MacUpdateTargetTests.cs |
Tests successful swaps, stale backups, failures, and rollback relaunch. |
src/UniGetUI.Core.Tools.Tests/LinuxUpdateTargetTests.cs |
Tests stale-backup recovery and restores permissions during cleanup. |
src/UniGetUI.Avalonia/Infrastructure/AvaloniaAutoUpdater.cs |
Uses the saved snapshot for startup warnings and previous-log viewing. |
Review effort: Balanced
There was a problem hiding this comment.
🤖 Pull request was approved automatically: the AI review is complete and all its review threads are resolved. 🎉
Integration Details
{
"deliveryId": "00e7f0c8-e828-11f1-913a-a54ca36dae5b",
"headSha": "600f41bacecc9e8f5d822423907581e836c36183",
"reviewer": "copilot-pull-request-reviewer[bot]"
}
Gabriel Dufresne (GabrielDuf)
deleted the
fix/macos-updater-stale-old-backup
branch
November 24, 2026 18:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug report
Users on 2026.3.4, which includes #5578, still see the macOS self-update close UniGetUI and reopen it on the same version. One affected user's
session.logshows 2026.3.5 downloaded, verified and extracted, thenReplacing /Applications/UniGetUI.app with the freshly-extracted bundle and relaunching., then 2026.3.4 starting again three seconds later, with nothing logged in between. On disk,/Applications/UniGetUI.appwas still 2026.3.4, and/Applications/UniGetUI.app.old, a 2026.3.1 copy, was owned byroot:wheel.Root cause
.pkg, so/Applications/UniGetUI.appwas owned by root.UniGetUI.app.oldworks, since an admin can write/Applications. Moving the new, user-owned app in works too. The finalrm -rf "$target.old"could not delete root-owned contents, and its failure was ignored.rm -rf "$target.old"fails silently.mv "$target" "$target.old"then finds.oldis still a folder, tries to move the app into it, and getsPermission denied. The script writes=== Swap failed:and relaunches the old app.InitializeSharedServicesAsync, before the main window exists, and on a connected Mac its firstResetUpdateLogoverwriteslast-update-attempt.log.CheckForOrphanedUpdateAttemptruns later fromMainWindowViewModeland finds a fresh log with no marker, so the "could not replace" banner from Stop the macOS updater swapping a translocated copy and failing silently #5578 never shows. The swap script also discardedmv's error.Both swap steps were reproduced in a scratch folder, with a read-only folder standing in for the root-owned one:
rm -rfexits 1 with.oldstill there, thenmv: rename UniGetUI.app to UniGetUI.app.old/UniGetUI.app: Permission denied.Fix
$target.old, it logs that and sets the old version aside under a unique$target.old.XXXXXXname. That name is deleted after a successful swap. The update then goes through with no prompt, and the stale root-owned folder is left as it was. Applied to the Linux swap script too, which had the same shape.mv's error and writes anUpdate swap failed while …: <reason>line, exactly as the Linux script already did;${2##*: }keeps only the reason, so no path reaches the log. Like Linux, if the rollback itself fails, it relaunches the old version from wherever it was left instead of the missing target.PreviousUpdateAttempt(UniGetUI.Core.Tools) reads the previous run's log once, the first time eitherResetUpdateLogorCheckForOrphanedUpdateAttemptasks, and keeps a copy inprevious-update-attempt.log.CheckForOrphanedUpdateAttemptworks from that snapshot, so its banners show whichever runs first, and their View log opens the copy. The "finished" marker is only appended while the previous attempt is still the file on disk.Regression tests
MacSwapScriptTests(new, macOS): the swap succeeds and opens the new version; it gets past an undeletable.oldwithout a failure marker and leaves no unique backup behind; it logsUpdate swap failed while moving the installed version aside: Permission deniedwith no path.openis pointed at a stub in the test's copy of the script, so nothing is launched.LinuxSwapScriptTests.SwapScript_SetsThePreviousVersionAsideWhenALeftoverBackupCannotBeDeleted(new).PreviousUpdateAttemptTests: the snapshot survives the log being overwritten and is copied; no previous log means nothing is reported, even if one appears later.main's scripts, the three new swap tests fail; with this change they pass. Filtered run of the updater test classes: 67 passed, 2 skipped (Linux-only), 0 failed.Verification
dotnet buildofUniGetUI.Avalonia(arm64) succeeds with no warnings in the changed files.mainnow restoresDevolutions.Pinget.Cli.Rust0.14.0 from a feed that needs credentials, so this compile used the local package cache with that pin rolled back to 0.13.0 locally; nothing of that is committed.dotnet format whitespaceanddotnet format stylewith--verify-no-changeson the changed files: exit 0.Not covered
/Applications/UniGetUI.app.oldas root once unblocks them (for Jamf-managed Macs, a one-line policy)..oldis left in place, since only root can delete it. The admin swap path (ElevatedSwapScript) still deletes it, as root, when it runs.