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

Commit

Permalink
delete plugin folder when uninstall plugin (#860)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim8y authored Jun 10, 2022
1 parent 584b866 commit 9512e05
Showing 1 changed file with 6 additions and 35 deletions.
41 changes: 6 additions & 35 deletions neo-cli/CLI/MainService.Plugins.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (C) 2016-2022 The Neo Project.
//
// The neo-cli is free software distributed under the MIT software
// license, see the accompanying file LICENSE in the main directory of
// the project or http://www.opensource.org/licenses/mit-license.php
// the project or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

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

/// <summary>
Expand All @@ -190,12 +189,6 @@ private void OnUnInstallCommand(string pluginName)
return;
}

var plugin = Plugin.Plugins.FirstOrDefault(p => p.Name == pluginName);
if (plugin is not null)
{
Plugin.Plugins.Remove(plugin);
}

foreach (var p in Plugin.Plugins)
{
try
Expand All @@ -207,7 +200,7 @@ private void OnUnInstallCommand(string pluginName)
.GetSection("Dependency")
.GetChildren()
.Select(d => d.Get<string>())
.Any(v => v == pluginName))
.Any(v => v.Equals(pluginName, StringComparison.InvariantCultureIgnoreCase)))
{
ConsoleHelper.Error(
$"Can not uninstall. Other plugins depend on this plugin, try `reinstall {pluginName}` if the plugin is broken.");
Expand All @@ -219,36 +212,14 @@ private void OnUnInstallCommand(string pluginName)
// ignored
}
}

try
{
DeleteFiles(new[] { $"Plugins/{pluginName}.dll", $"Plugins/{pluginName}/config.json" });
Directory.Delete($"Plugins/{pluginName}", false);
}
catch (IOException)
{
Directory.Delete($"Plugins/{pluginName}", true);
}

catch (IOException) { }
ConsoleHelper.Info("Uninstall successful, please restart neo-cli.");
}

private static void DeleteFiles(IEnumerable<string> list)
{
foreach (var file in list)
{
try
{
if (!File.Exists(file)) continue;
ConsoleHelper.Info("Deleting ", file);
File.Delete(file);
}
catch (Exception)
{
// ignored
}
}
}

/// <summary>
/// Process "plugins" command
/// </summary>
Expand Down

0 comments on commit 9512e05

Please sign in to comment.