Fixed deletion of the existing assistant plugin when its backup failed

This commit is contained in:
Thorsten Sommer 2026-08-05 16:22:59 +02:00
parent e0057b67ae
commit c50ca0dd54
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -427,6 +427,7 @@ public sealed class AssistantPluginInstallService
string? backupDirectory = null; string? backupDirectory = null;
string? finalDirectory = null; string? finalDirectory = null;
var replacedExisting = false; var replacedExisting = false;
var movedIntoPlace = false;
try try
{ {
@ -443,6 +444,7 @@ public sealed class AssistantPluginInstallService
} }
Directory.Move(stagingDirectory, finalDirectory); Directory.Move(stagingDirectory, finalDirectory);
movedIntoPlace = true;
await PluginFactory.LoadAll(token); await PluginFactory.LoadAll(token);
if (!string.IsNullOrWhiteSpace(backupDirectory)) if (!string.IsNullOrWhiteSpace(backupDirectory))
@ -455,7 +457,10 @@ public sealed class AssistantPluginInstallService
{ {
this.logger.LogError(e, "Failed to install assistant plugin."); this.logger.LogError(e, "Failed to install assistant plugin.");
if (!string.IsNullOrWhiteSpace(finalDirectory) && Directory.Exists(finalDirectory)) // Only remove the target directory when this installation actually moved the plugin
// there. Otherwise, when moving the previous plugin into the backup directory failed,
// we would delete the still intact previous plugin:
if (movedIntoPlace && !string.IsNullOrWhiteSpace(finalDirectory) && Directory.Exists(finalDirectory))
TryDeleteDirectory(finalDirectory, "failed assistant plugin installation", this.logger); TryDeleteDirectory(finalDirectory, "failed assistant plugin installation", this.logger);
if (!string.IsNullOrWhiteSpace(backupDirectory) && Directory.Exists(backupDirectory) && !string.IsNullOrWhiteSpace(finalDirectory) && !Directory.Exists(finalDirectory)) if (!string.IsNullOrWhiteSpace(backupDirectory) && Directory.Exists(backupDirectory) && !string.IsNullOrWhiteSpace(finalDirectory) && !Directory.Exists(finalDirectory))