PR: Sub Issue 11+12 - GracefulExit utility#332
Merged
Conversation
- StorageManager.Restore() — restore from backup to install path - StorageManager.CleanBackup() — keep only N most recent backups - StorageManager.ListBackups() — query backup metadata - BackupConfig — version retention, skip dirs, enable/disable - BackupInfo record — version, path, timestamp, size Closes #327
…ooks - IUpdateHooks interface with 5 lifecycle callbacks - UpdateContext / DownloadContext records - NoOpUpdateHooks (default pass-through) - UnixPermissionHooks: chmod +x for Linux/macOS - CustomPermissionHooks: user-supplied permission script Closes #329
- CloseMainWindow() + timeout fallback to Kill() - Current process shutdown helper - Replaces raw Process.Kill() calls across the codebase Closes #331
Contributor
There was a problem hiding this comment.
Pull request overview
Introduces new lifecycle-hook abstractions and a GracefulExit helper intended to replace raw Process.Kill() usage, and extends StorageManager with backup-related utilities.
Changes:
- Add
GracefulExitutility for graceful process shutdown with timeout + kill fallback. - Add
IUpdateHooksplus default/no-op and permission-related hook implementations. - Add backup restore/list/cleanup helpers plus backup metadata/config types in
StorageManager.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
src/c#/GeneralUpdate.Core/Hooks/IUpdateHooks.cs |
Adds hook interface + contexts and default/permission hook implementations. |
src/c#/GeneralUpdate.Core/GracefulExit.cs |
Adds process shutdown helper intended to replace direct Process.Kill(). |
src/c#/GeneralUpdate.Core/FileSystem/StorageManager.cs |
Adds backup restore/retention/listing helpers and backup metadata/config types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+14
to
+18
| if (process == null || process.HasExited) return; | ||
| if (!process.CloseMainWindow()) | ||
| await Task.Delay(timeoutMs).ConfigureAwait(false); | ||
| if (!process.HasExited) | ||
| process.Kill(); // Last resort |
| /// <summary>Shutdown the current process gracefully.</summary> | ||
| public static async Task CurrentProcessAsync(int timeoutMs = 3000) | ||
| { | ||
| var p = Process.GetCurrentProcess(); |
| using System.Diagnostics; | ||
| using System.IO; | ||
| using System.Threading.Tasks; | ||
| using GeneralUpdate.Core.Configuration; |
Comment on lines
+49
to
+54
| public async Task OnBeforeStartAppAsync(UpdateContext ctx) | ||
| { | ||
| var mainApp = Path.Combine(ctx.InstallPath, ctx.AppName); | ||
| if (File.Exists(mainApp)) | ||
| await Process.Start("chmod", $"+x \"{mainApp}\"").WaitForExitAsync(); | ||
| } |
Comment on lines
+74
to
+78
| using var proc = Process.Start(psi)!; | ||
| await proc.WaitForExitAsync(); | ||
| if (proc.ExitCode != 0) | ||
| throw new InvalidOperationException( | ||
| $"Permission script '{_scriptPath}' failed (exit {proc.ExitCode})"); |
| private void ResetId() => Interlocked.Exchange(ref _fileCount, 0); | ||
|
|
||
| /// <summary>Restore files from backup directory to install path.</summary> | ||
| public static void Restore(string backupDir, string installPath) |
Comment on lines
+292
to
+295
| foreach (var file in Directory.GetFiles(backupDir, "*", SearchOption.AllDirectories)) | ||
| { | ||
| var relativePath = file.Substring(backupDir.Length).TrimStart(Path.DirectorySeparatorChar); | ||
| var dest = Path.Combine(installPath, relativePath); |
Comment on lines
+301
to
+310
| /// <summary>Clean old backups, keeping only the N most recent versions.</summary> | ||
| public static void CleanBackup(string installPath, int keepVersions = 3) | ||
| { | ||
| var backupRoot = Path.Combine(installPath, "__backups"); | ||
| if (!Directory.Exists(backupRoot)) return; | ||
|
|
||
| var dirs = Directory.GetDirectories(backupRoot) | ||
| .Select(d => new DirectoryInfo(d)) | ||
| .OrderByDescending(d => d.CreationTime) | ||
| .Skip(keepVersions); |
Comment on lines
+307
to
+310
| var dirs = Directory.GetDirectories(backupRoot) | ||
| .Select(d => new DirectoryInfo(d)) | ||
| .OrderByDescending(d => d.CreationTime) | ||
| .Skip(keepVersions); |
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.
Summary
Closes #331
Changes
Replaces raw \Process.Kill()\ calls throughout the codebase.
Build
✅ 0 errors