Skip to content
This repository was archived by the owner on Dec 7, 2023. It is now read-only.

Commit 9512e05

Browse files
authored
delete plugin folder when uninstall plugin (#860)
1 parent 584b866 commit 9512e05

File tree

1 file changed

+6
-35
lines changed

1 file changed

+6
-35
lines changed

neo-cli/CLI/MainService.Plugins.cs

+6-35
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// Copyright (C) 2016-2022 The Neo Project.
2-
//
32
// The neo-cli is free software distributed under the MIT software
43
// license, see the accompanying file LICENSE in the main directory of
5-
// the project or http://www.opensource.org/licenses/mit-license.php
4+
// the project or http://www.opensource.org/licenses/mit-license.php
65
// for more details.
7-
//
6+
//
87
// Redistribution and use in source and binary forms with or without
98
// modifications are permitted.
109

@@ -174,7 +173,7 @@ private async Task InstallDependenciesAsync(Stream config, HashSet<string> insta
174173
/// <returns></returns>
175174
private static bool PluginExists(string pluginName)
176175
{
177-
return File.Exists($"Plugins/{pluginName}.dll");
176+
return Plugin.Plugins.Any(p => p.Name.Equals(pluginName, StringComparison.InvariantCultureIgnoreCase));
178177
}
179178

180179
/// <summary>
@@ -190,12 +189,6 @@ private void OnUnInstallCommand(string pluginName)
190189
return;
191190
}
192191

193-
var plugin = Plugin.Plugins.FirstOrDefault(p => p.Name == pluginName);
194-
if (plugin is not null)
195-
{
196-
Plugin.Plugins.Remove(plugin);
197-
}
198-
199192
foreach (var p in Plugin.Plugins)
200193
{
201194
try
@@ -207,7 +200,7 @@ private void OnUnInstallCommand(string pluginName)
207200
.GetSection("Dependency")
208201
.GetChildren()
209202
.Select(d => d.Get<string>())
210-
.Any(v => v == pluginName))
203+
.Any(v => v.Equals(pluginName, StringComparison.InvariantCultureIgnoreCase)))
211204
{
212205
ConsoleHelper.Error(
213206
$"Can not uninstall. Other plugins depend on this plugin, try `reinstall {pluginName}` if the plugin is broken.");
@@ -219,36 +212,14 @@ private void OnUnInstallCommand(string pluginName)
219212
// ignored
220213
}
221214
}
222-
223215
try
224216
{
225-
DeleteFiles(new[] { $"Plugins/{pluginName}.dll", $"Plugins/{pluginName}/config.json" });
226-
Directory.Delete($"Plugins/{pluginName}", false);
227-
}
228-
catch (IOException)
229-
{
217+
Directory.Delete($"Plugins/{pluginName}", true);
230218
}
231-
219+
catch (IOException) { }
232220
ConsoleHelper.Info("Uninstall successful, please restart neo-cli.");
233221
}
234222

235-
private static void DeleteFiles(IEnumerable<string> list)
236-
{
237-
foreach (var file in list)
238-
{
239-
try
240-
{
241-
if (!File.Exists(file)) continue;
242-
ConsoleHelper.Info("Deleting ", file);
243-
File.Delete(file);
244-
}
245-
catch (Exception)
246-
{
247-
// ignored
248-
}
249-
}
250-
}
251-
252223
/// <summary>
253224
/// Process "plugins" command
254225
/// </summary>

0 commit comments

Comments
 (0)