Changes as recommended.

This commit is contained in:
Greenback 2020-12-15 16:37:11 +00:00
parent c761cbff0e
commit eb2439f23b
6 changed files with 35 additions and 57 deletions

View File

@ -396,7 +396,7 @@ namespace Emby.Server.Implementations
Logger.LogError("DI Loop detected in the attempted creation of {Type}", type.FullName); Logger.LogError("DI Loop detected in the attempted creation of {Type}", type.FullName);
foreach (var entry in _creatingInstances) foreach (var entry in _creatingInstances)
{ {
Logger.LogError("Called from: {stack}", entry.FullName); Logger.LogError("Called from: {TypeName}", entry.FullName);
} }
_pluginManager.FailPlugin(type.Assembly); _pluginManager.FailPlugin(type.Assembly);

View File

@ -96,9 +96,10 @@ namespace Emby.Server.Implementations
foreach (var file in plugin.DllFiles) foreach (var file in plugin.DllFiles)
{ {
Assembly assembly;
try try
{ {
plugin.Assembly = Assembly.LoadFrom(file); assembly = Assembly.LoadFrom(file);
} }
catch (FileLoadException ex) catch (FileLoadException ex)
{ {
@ -107,8 +108,8 @@ namespace Emby.Server.Implementations
continue; continue;
} }
_logger.LogInformation("Loaded assembly {Assembly} from {Path}", plugin.Assembly.FullName, file); _logger.LogInformation("Loaded assembly {Assembly} from {Path}", assembly.FullName, file);
yield return plugin.Assembly; yield return assembly;
} }
} }
} }
@ -203,6 +204,7 @@ namespace Emby.Server.Implementations
return true; return true;
} }
_logger.LogWarning("Unable to delete {Path}, so marking as deleteOnStartup.", plugin.Path);
// Unable to delete, so disable. // Unable to delete, so disable.
return ChangePluginState(plugin, PluginStatus.DeleteOnStartup); return ChangePluginState(plugin, PluginStatus.DeleteOnStartup);
} }
@ -310,10 +312,7 @@ namespace Emby.Server.Implementations
throw new ArgumentNullException(nameof(assembly)); throw new ArgumentNullException(nameof(assembly));
} }
var plugin = _plugins.Where( var plugin = _plugins.Where(p => p.DllFiles.Contains(assembly.Location)).FirstOrDefault();
p => assembly.Equals(p.Assembly)
|| string.Equals(assembly.Location, assembly.Location, StringComparison.OrdinalIgnoreCase))
.FirstOrDefault();
if (plugin == null) if (plugin == null)
{ {
// A plugin's assembly didn't cause this issue, so ignore it. // A plugin's assembly didn't cause this issue, so ignore it.
@ -366,20 +365,7 @@ namespace Emby.Server.Implementations
} }
plugin.Manifest.Status = state; plugin.Manifest.Status = state;
SaveManifest(plugin.Manifest, plugin.Path); return SaveManifest(plugin.Manifest, plugin.Path);
try
{
var data = JsonSerializer.Serialize(plugin.Manifest, _jsonOptions);
File.WriteAllText(Path.Combine(plugin.Path, "meta.json"), data, Encoding.UTF8);
return true;
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception e)
#pragma warning restore CA1031 // Do not catch general exception types
{
_logger.LogWarning(e, "Unable to disable plugin {Path}", plugin.Path);
return false;
}
} }
/// <summary> /// <summary>
@ -509,15 +495,14 @@ namespace Emby.Server.Implementations
// Attempt a cleanup of old folders. // Attempt a cleanup of old folders.
try try
{ {
_logger.LogDebug("Deleting {Path}", plugin.Path);
Directory.Delete(plugin.Path, true); Directory.Delete(plugin.Path, true);
_logger.LogDebug("Deleted {Path}", plugin.Path);
_plugins.Remove(plugin); _plugins.Remove(plugin);
} }
#pragma warning disable CA1031 // Do not catch general exception types #pragma warning disable CA1031 // Do not catch general exception types
catch (Exception e) catch
#pragma warning restore CA1031 // Do not catch general exception types #pragma warning restore CA1031 // Do not catch general exception types
{ {
_logger.LogWarning(e, "Unable to delete {Path}", plugin.Path);
return false; return false;
} }
@ -670,21 +655,23 @@ namespace Emby.Server.Implementations
_logger.LogWarning(e, "Unable to delete {Path}", path); _logger.LogWarning(e, "Unable to delete {Path}", path);
} }
versions.RemoveAt(x); if (cleaned)
}
if (!cleaned)
{
if (manifest == null)
{ {
_logger.LogWarning("Unable to disable plugin {Path}", entry.Path); versions.RemoveAt(x);
continue;
} }
else
if (manifest.Status != PluginStatus.DeleteOnStartup)
{ {
manifest.Status = PluginStatus.DeleteOnStartup; if (manifest == null)
SaveManifest(manifest, entry.Path); {
_logger.LogWarning("Unable to disable plugin {Path}", entry.Path);
continue;
}
if (manifest.Status != PluginStatus.DeleteOnStartup)
{
manifest.Status = PluginStatus.DeleteOnStartup;
SaveManifest(manifest, entry.Path);
}
} }
} }
} }

View File

@ -8,7 +8,6 @@ using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Json; using System.Net.Http.Json;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -106,18 +105,8 @@ namespace Emby.Server.Implementations.Updates
try try
{ {
List<PackageInfo>? packages; List<PackageInfo>? packages;
var uri = new Uri(manifest); packages = await _httpClientFactory.CreateClient(NamedClient.Default)
if (uri.Scheme.StartsWith("http", StringComparison.OrdinalIgnoreCase)) .GetFromJsonAsync<List<PackageInfo>>(new Uri(manifest), _jsonSerializerOptions, cancellationToken).ConfigureAwait(false);
{
packages = await _httpClientFactory.CreateClient(NamedClient.Default)
.GetFromJsonAsync<List<PackageInfo>>(uri, _jsonSerializerOptions, cancellationToken).ConfigureAwait(false);
}
else
{
// Local Packages
var data = File.ReadAllText(manifest, Encoding.UTF8);
packages = JsonSerializer.Deserialize<List<PackageInfo>>(data, _jsonSerializerOptions);
}
if (packages == null) if (packages == null)
{ {

View File

@ -44,7 +44,6 @@ namespace Jellyfin.Api.Controllers
/// <returns>A <see cref="PackageInfo"/> containing package information.</returns> /// <returns>A <see cref="PackageInfo"/> containing package information.</returns>
[HttpGet("Packages/{name}")] [HttpGet("Packages/{name}")]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[Produces(JsonDefaults.CamelCaseMediaType)]
public async Task<ActionResult<PackageInfo>> GetPackageInfo( public async Task<ActionResult<PackageInfo>> GetPackageInfo(
[FromRoute, Required] string name, [FromRoute, Required] string name,
[FromQuery] Guid? assemblyGuid) [FromQuery] Guid? assemblyGuid)
@ -71,7 +70,6 @@ namespace Jellyfin.Api.Controllers
/// <returns>An <see cref="PackageInfo"/> containing available packages information.</returns> /// <returns>An <see cref="PackageInfo"/> containing available packages information.</returns>
[HttpGet("Packages")] [HttpGet("Packages")]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[Produces(JsonDefaults.CamelCaseMediaType)]
public async Task<IEnumerable<PackageInfo>> GetPackages() public async Task<IEnumerable<PackageInfo>> GetPackages()
{ {
IEnumerable<PackageInfo> packages = await _installationManager.GetAvailablePackages().ConfigureAwait(false); IEnumerable<PackageInfo> packages = await _installationManager.GetAvailablePackages().ConfigureAwait(false);

View File

@ -80,11 +80,6 @@ namespace MediaBrowser.Common.Plugins
/// </summary> /// </summary>
public PluginManifest Manifest { get; } public PluginManifest Manifest { get; }
/// <summary>
/// Gets or sets a value indicating the assembly of the plugin.
/// </summary>
public Assembly? Assembly { get; set; }
/// <summary> /// <summary>
/// Compare two <see cref="LocalPlugin"/>. /// Compare two <see cref="LocalPlugin"/>.
/// </summary> /// </summary>

View File

@ -1,6 +1,7 @@
#nullable enable #nullable enable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace MediaBrowser.Model.Updates namespace MediaBrowser.Model.Updates
{ {
@ -27,30 +28,35 @@ namespace MediaBrowser.Model.Updates
/// Gets or sets the name. /// Gets or sets the name.
/// </summary> /// </summary>
/// <value>The name.</value> /// <value>The name.</value>
[JsonPropertyName("name")]
public string Name { get; set; } public string Name { get; set; }
/// <summary> /// <summary>
/// Gets or sets a long description of the plugin containing features or helpful explanations. /// Gets or sets a long description of the plugin containing features or helpful explanations.
/// </summary> /// </summary>
/// <value>The description.</value> /// <value>The description.</value>
/// [JsonPropertyName("description")]
public string Description { get; set; } public string Description { get; set; }
/// <summary> /// <summary>
/// Gets or sets a short overview of what the plugin does. /// Gets or sets a short overview of what the plugin does.
/// </summary> /// </summary>
/// <value>The overview.</value> /// <value>The overview.</value>
[JsonPropertyName("overview")]
public string Overview { get; set; } public string Overview { get; set; }
/// <summary> /// <summary>
/// Gets or sets the owner. /// Gets or sets the owner.
/// </summary> /// </summary>
/// <value>The owner.</value> /// <value>The owner.</value>
[JsonPropertyName("owner")]
public string Owner { get; set; } public string Owner { get; set; }
/// <summary> /// <summary>
/// Gets or sets the category. /// Gets or sets the category.
/// </summary> /// </summary>
/// <value>The category.</value> /// <value>The category.</value>
[JsonPropertyName("category")]
public string Category { get; set; } public string Category { get; set; }
/// <summary> /// <summary>
@ -58,6 +64,7 @@ namespace MediaBrowser.Model.Updates
/// This is used to identify the proper item for automatic updates. /// This is used to identify the proper item for automatic updates.
/// </summary> /// </summary>
/// <value>The name.</value> /// <value>The name.</value>
[JsonPropertyName("guid")]
#pragma warning disable CA1720 // Identifier contains type name #pragma warning disable CA1720 // Identifier contains type name
public string Guid { get; set; } public string Guid { get; set; }
#pragma warning restore CA1720 // Identifier contains type name #pragma warning restore CA1720 // Identifier contains type name
@ -66,6 +73,7 @@ namespace MediaBrowser.Model.Updates
/// Gets or sets the versions. /// Gets or sets the versions.
/// </summary> /// </summary>
/// <value>The versions.</value> /// <value>The versions.</value>
[JsonPropertyName("versions")]
#pragma warning disable CA2227 // Collection properties should be read only #pragma warning disable CA2227 // Collection properties should be read only
public IList<VersionInfo> Versions { get; set; } public IList<VersionInfo> Versions { get; set; }
#pragma warning restore CA2227 // Collection properties should be read only #pragma warning restore CA2227 // Collection properties should be read only
@ -73,6 +81,7 @@ namespace MediaBrowser.Model.Updates
/// <summary> /// <summary>
/// Gets or sets the image url for the package. /// Gets or sets the image url for the package.
/// </summary> /// </summary>
[JsonPropertyName("imageUrl")]
public string? ImageUrl { get; set; } public string? ImageUrl { get; set; }
} }
} }