Repository navigation
chore: Simplify native CLI uninstall completion handling #1622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hatayama
merged 1 commit into
v3-beta
from
refactor/hatayama/extract-native-cli-uninstall-waiter
Jul 8, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
144 changes: 144 additions & 0 deletions
144
Packages/src/Editor/Infrastructure/CLI/NativeCliUninstallCompletionWaiter.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| using UnityEngine; | ||
|
|
||
| using io.github.hatayama.UnityCliLoop.Application; | ||
|
|
||
| namespace io.github.hatayama.UnityCliLoop.Infrastructure | ||
| { | ||
| /// <summary> | ||
| /// Waits for native CLI uninstall cleanup to finish. | ||
| /// </summary> | ||
| internal static class NativeCliUninstallCompletionWaiter | ||
| { | ||
| internal const int UNINSTALL_COMPLETION_TIMEOUT_MS = 30000; | ||
|
|
||
| internal static async Task<CliInstallResult> WaitForUninstallTargetRemovalAsync( | ||
| string targetPath, | ||
| CancellationToken ct, | ||
| int timeoutMs, | ||
| int pollMs, | ||
| Func<string, bool> fileExists, | ||
| Func<int, CancellationToken, Task> delayAsync) | ||
| { | ||
| UnityEngine.Debug.Assert(!string.IsNullOrWhiteSpace(targetPath), "targetPath must not be null or empty"); | ||
| UnityEngine.Debug.Assert(timeoutMs > 0, "timeoutMs must be greater than zero"); | ||
| UnityEngine.Debug.Assert(pollMs > 0, "pollMs must be greater than zero"); | ||
| UnityEngine.Debug.Assert(fileExists != null, "fileExists must not be null"); | ||
| UnityEngine.Debug.Assert(delayAsync != null, "delayAsync must not be null"); | ||
|
|
||
| int elapsedMs = 0; | ||
| while (fileExists(targetPath)) | ||
| { | ||
| ct.ThrowIfCancellationRequested(); | ||
| if (elapsedMs >= timeoutMs) | ||
| { | ||
| return new CliInstallResult( | ||
| false, | ||
| $"Timed out waiting for uLoop CLI uninstall to remove {targetPath}."); | ||
| } | ||
|
|
||
| int delayMs = Math.Min(pollMs, timeoutMs - elapsedMs); | ||
| await delayAsync(delayMs, ct); | ||
| elapsedMs += delayMs; | ||
| } | ||
|
|
||
| return new CliInstallResult(true, ""); | ||
| } | ||
|
|
||
| internal static async Task<CliInstallResult> WaitForUninstallCompletionAsync( | ||
| string targetPath, | ||
| string installDirectory, | ||
| RuntimePlatform platform, | ||
| CancellationToken ct, | ||
| int timeoutMs, | ||
| int pollMs, | ||
| Func<string, bool> fileExists, | ||
| bool requireUserPathRemoval, | ||
| Func<string, EnvironmentVariableTarget, string> getEnvironmentVariable, | ||
| Func<int, CancellationToken, Task> delayAsync) | ||
| { | ||
| UnityEngine.Debug.Assert(!string.IsNullOrWhiteSpace(targetPath), "targetPath must not be null or empty"); | ||
| UnityEngine.Debug.Assert(!string.IsNullOrWhiteSpace(installDirectory), "installDirectory must not be null or empty"); | ||
| UnityEngine.Debug.Assert(timeoutMs > 0, "timeoutMs must be greater than zero"); | ||
| UnityEngine.Debug.Assert(pollMs > 0, "pollMs must be greater than zero"); | ||
| UnityEngine.Debug.Assert(fileExists != null, "fileExists must not be null"); | ||
| UnityEngine.Debug.Assert(getEnvironmentVariable != null, "getEnvironmentVariable must not be null"); | ||
| UnityEngine.Debug.Assert(delayAsync != null, "delayAsync must not be null"); | ||
|
|
||
| int elapsedMs = 0; | ||
| while (true) | ||
| { | ||
| bool targetStillExists = fileExists(targetPath); | ||
| bool userPathStillContainsInstallDirectory = ShouldWaitForUserPathRemoval( | ||
| requireUserPathRemoval, | ||
| installDirectory, | ||
| platform, | ||
| getEnvironmentVariable); | ||
| if (!targetStillExists && !userPathStillContainsInstallDirectory) | ||
| { | ||
| return new CliInstallResult(true, ""); | ||
| } | ||
|
|
||
| ct.ThrowIfCancellationRequested(); | ||
| if (elapsedMs >= timeoutMs) | ||
| { | ||
| return new CliInstallResult( | ||
| false, | ||
| BuildUninstallCompletionTimeoutFailure( | ||
| targetPath, | ||
| installDirectory, | ||
| platform, | ||
| targetStillExists, | ||
| userPathStillContainsInstallDirectory)); | ||
| } | ||
|
|
||
| int delayMs = Math.Min(pollMs, timeoutMs - elapsedMs); | ||
| await delayAsync(delayMs, ct); | ||
| elapsedMs += delayMs; | ||
| } | ||
| } | ||
|
|
||
| private static bool ShouldWaitForUserPathRemoval( | ||
| bool requireUserPathRemoval, | ||
| string installDirectory, | ||
| RuntimePlatform platform, | ||
| Func<string, EnvironmentVariableTarget, string> getEnvironmentVariable) | ||
| { | ||
| UnityEngine.Debug.Assert(!string.IsNullOrWhiteSpace(installDirectory), "installDirectory must not be null or empty"); | ||
| UnityEngine.Debug.Assert(getEnvironmentVariable != null, "getEnvironmentVariable must not be null"); | ||
|
|
||
| return requireUserPathRemoval | ||
| && NativeCliInstallPathResolver.DoesUserPathContainInstallDirectory( | ||
| installDirectory, | ||
| platform, | ||
| getEnvironmentVariable); | ||
| } | ||
|
|
||
| private static string BuildUninstallCompletionTimeoutFailure( | ||
| string targetPath, | ||
| string installDirectory, | ||
| RuntimePlatform platform, | ||
| bool targetStillExists, | ||
| bool userPathStillContainsInstallDirectory) | ||
| { | ||
| UnityEngine.Debug.Assert(!string.IsNullOrWhiteSpace(targetPath), "targetPath must not be null or empty"); | ||
| UnityEngine.Debug.Assert(!string.IsNullOrWhiteSpace(installDirectory), "installDirectory must not be null or empty"); | ||
| UnityEngine.Debug.Assert(targetStillExists || userPathStillContainsInstallDirectory, "at least one uninstall cleanup condition must still be pending"); | ||
|
|
||
| if (platform != RuntimePlatform.WindowsEditor || !userPathStillContainsInstallDirectory) | ||
| { | ||
| return $"Timed out waiting for uLoop CLI uninstall to remove {targetPath}."; | ||
| } | ||
|
|
||
| if (!targetStillExists) | ||
| { | ||
| return $"Timed out waiting for uLoop CLI uninstall to remove {installDirectory} from Windows User PATH."; | ||
| } | ||
|
|
||
| return $"Timed out waiting for uLoop CLI uninstall to remove {targetPath} and remove {installDirectory} from Windows User PATH."; | ||
| } | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
Packages/src/Editor/Infrastructure/CLI/NativeCliUninstallCompletionWaiter.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.