Rework plugin deletion + misc (#927)

* fix: stuck overlay on errors

* feat: delete old plugin versions

* feat: ignore error tag when outdated, banned, or orphaned

* feat: rework plugin deletion
This commit is contained in:
Aireil 2022-07-23 15:47:24 +02:00 committed by GitHub
parent 62831f8d1e
commit 1574ef7c33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 97 additions and 19 deletions

View file

@ -848,10 +848,17 @@ internal partial class PluginManager : IDisposable, IServiceType
}
else
{
foreach (var versionDir in versionDirs)
for (var i = 0; i < versionDirs.Length; i++)
{
var versionDir = versionDirs[i];
try
{
if (i != 0)
{
Log.Information($"Old version: cleaning up {versionDir.FullName}");
versionDir.Delete(true);
continue;
}
var dllFile = new FileInfo(Path.Combine(versionDir.FullName, $"{pluginDir.Name}.dll"));
if (!dllFile.Exists)
{
@ -865,6 +872,21 @@ internal partial class PluginManager : IDisposable, IServiceType
{
Log.Information($"Missing manifest: cleaning up {versionDir.FullName}");
versionDir.Delete(true);
continue;
}
if (manifestFile.Length == 0)
{
Log.Information($"Manifest empty: cleaning up {versionDir.FullName}");
versionDir.Delete(true);
continue;
}
var manifest = LocalPluginManifest.Load(manifestFile);
if (manifest.ScheduledForDeletion)
{
Log.Information($"Scheduled deletion: cleaning up {versionDir.FullName}");
versionDir.Delete(true);
}
}
catch (Exception ex)
@ -902,6 +924,9 @@ internal partial class PluginManager : IDisposable, IServiceType
if (plugin.InstalledPlugin.Manifest.Disabled && ignoreDisabled)
continue;
if (plugin.InstalledPlugin.Manifest.ScheduledForDeletion)
continue;
var result = await this.UpdateSinglePluginAsync(plugin, false, dryRun);
if (result != null)
updatedList.Add(result);

View file

@ -560,6 +560,7 @@ internal class LocalPlugin : IDisposable
throw new InvalidPluginOperationException($"Unable to enable {this.Name}, not disabled");
this.Manifest.Disabled = false;
this.Manifest.ScheduledForDeletion = false;
this.SaveManifest();
}
@ -614,6 +615,16 @@ internal class LocalPlugin : IDisposable
this.SaveManifest();
}
/// <summary>
/// Schedule the deletion of this plugin on next cleanup.
/// </summary>
/// <param name="status">Schedule or cancel the deletion.</param>
public void ScheduleDeletion(bool status = true)
{
this.Manifest.ScheduledForDeletion = status;
this.SaveManifest();
}
private static void SetupLoaderConfig(LoaderConfig config)
{
config.IsUnloadable = true;

View file

@ -24,6 +24,11 @@ internal record LocalPluginManifest : PluginManifest
/// </summary>
public bool Testing { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the plugin should be deleted during the next cleanup.
/// </summary>
public bool ScheduledForDeletion { get; set; }
/// <summary>
/// Gets or sets the 3rd party repo URL that this plugin was installed from. Used to display where the plugin was
/// sourced from on the installed plugin view. This should not be included in the plugin master. This value is null