PR: Sub Issue 10 - IUpdateHooks + UnixPermissionHooks#330
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
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces an update lifecycle hook surface (IUpdateHooks) plus built-in permission hooks (chmod +x and custom script) and extends StorageManager with backup/restore utilities to support the GeneralUpdate v2 refactor plan (closes #329).
Changes:
- Add
IUpdateHookswith lifecycle callbacks and associatedUpdateContext/DownloadContextrecords, plus default implementations (NoOpUpdateHooks,UnixPermissionHooks,CustomPermissionHooks). - Add backup management helpers in
StorageManager(restore-from-dir, cleanup, list backups) and backup metadata/config types.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/c#/GeneralUpdate.Core/Hooks/IUpdateHooks.cs | Adds lifecycle hook interface + default implementations, including Unix chmod and custom permission script hook. |
| src/c#/GeneralUpdate.Core/FileSystem/StorageManager.cs | Adds backup restore/cleanup/list helpers and introduces backup config/metadata types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+286
to
+299
| /// <summary>Restore files from backup directory to install path.</summary> | ||
| public static void Restore(string backupDir, string installPath) | ||
| { | ||
| if (!Directory.Exists(backupDir)) | ||
| throw new DirectoryNotFoundException($"Backup directory not found: {backupDir}"); | ||
|
|
||
| foreach (var file in Directory.GetFiles(backupDir, "*", SearchOption.AllDirectories)) | ||
| { | ||
| var relativePath = file.Substring(backupDir.Length).TrimStart(Path.DirectorySeparatorChar); | ||
| var dest = Path.Combine(installPath, relativePath); | ||
| Directory.CreateDirectory(Path.GetDirectoryName(dest)!); | ||
| File.Copy(file, dest, true); | ||
| } | ||
| } |
Comment on lines
+301
to
+306
| /// <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; | ||
|
|
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
+68
to
+79
| public async Task OnBeforeStartAppAsync(UpdateContext ctx) | ||
| { | ||
| var psi = new ProcessStartInfo(_scriptPath, ctx.InstallPath) | ||
| { | ||
| RedirectStandardOutput = true, RedirectStandardError = true | ||
| }; | ||
| using var proc = Process.Start(psi)!; | ||
| await proc.WaitForExitAsync(); | ||
| if (proc.ExitCode != 0) | ||
| throw new InvalidOperationException( | ||
| $"Permission script '{_scriptPath}' failed (exit {proc.ExitCode})"); | ||
| } |
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 #329
Changes
Build
✅ 0 errors