升级插件安全策略、包管理和运行时能力
This commit is contained in:
@@ -9,6 +9,8 @@ namespace YMhut.Box.Core.Plugins;
|
||||
public interface IBuiltInPluginInstallerService
|
||||
{
|
||||
Task EnsureInstalledAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
Task<bool> ResetAsync(string pluginId, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
public sealed class BuiltInPluginInstallerService(
|
||||
@@ -68,6 +70,31 @@ public sealed class BuiltInPluginInstallerService(
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> ResetAsync(string pluginId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await _gate.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
var plugin = DiscoverEmbeddedPlugins().FirstOrDefault(item => string.Equals(item.FolderName, pluginId, StringComparison.OrdinalIgnoreCase));
|
||||
if (plugin is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var targetRoot = Path.Combine(PluginsRoot, plugin.FolderName);
|
||||
if (Directory.Exists(targetRoot))
|
||||
{
|
||||
Directory.Delete(targetRoot, recursive: true);
|
||||
}
|
||||
await ExtractEmbeddedPluginAsync(plugin, targetRoot, cancellationToken).ConfigureAwait(false);
|
||||
await WriteLogAsync("Information", "Built-in plugin reset", targetRoot, cancellationToken).ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_gate.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<bool> IsUnmodifiedBuiltInPluginAsync(string targetRoot, CancellationToken cancellationToken)
|
||||
{
|
||||
var fingerprintPath = Path.Combine(targetRoot, FingerprintFileName);
|
||||
|
||||
Reference in New Issue
Block a user