Skip to content

PR: Sub Issue 10 - IUpdateHooks + UnixPermissionHooks#330

Merged
JusterZhu merged 2 commits into
masterfrom
feature/hooks
May 24, 2026
Merged

PR: Sub Issue 10 - IUpdateHooks + UnixPermissionHooks#330
JusterZhu merged 2 commits into
masterfrom
feature/hooks

Conversation

@JusterZhu
Copy link
Copy Markdown
Collaborator

Summary

Closes #329

Changes

  • \IUpdateHooks\ — 5 lifecycle callbacks (BeforeUpdate/DownloadCompleted/AfterUpdate/Error/BeforeStartApp)
  • \UpdateContext\ / \DownloadContext\ — context records
  • \NoOpUpdateHooks\ — default pass-through
  • \UnixPermissionHooks\ — built-in chmod +x
  • \CustomPermissionHooks\ — user-supplied permission script

Build

✅ 0 errors

JusterZhu added 2 commits May 24, 2026 08:10
- 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
Copilot AI review requested due to automatic review settings May 24, 2026 00:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 IUpdateHooks with lifecycle callbacks and associated UpdateContext / DownloadContext records, 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})");
}
@JusterZhu JusterZhu merged commit f8e3b86 into master May 24, 2026
1 check passed
@JusterZhu JusterZhu deleted the feature/hooks branch May 24, 2026 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sub Issue 10: IUpdateHooks + UnixPermissionHooks + CustomPermissionHooks

2 participants