diff --git a/PlugHub.Shared/Attributes/ProvidesDescriptorAttribute.cs b/PlugHub.Shared/Attributes/DescriptorProviderAttribute.cs similarity index 84% rename from PlugHub.Shared/Attributes/ProvidesDescriptorAttribute.cs rename to PlugHub.Shared/Attributes/DescriptorProviderAttribute.cs index a6c6287..622e8b9 100644 --- a/PlugHub.Shared/Attributes/ProvidesDescriptorAttribute.cs +++ b/PlugHub.Shared/Attributes/DescriptorProviderAttribute.cs @@ -1,7 +1,7 @@ namespace PlugHub.Shared.Attributes { [AttributeUsage(AttributeTargets.Interface, Inherited = false)] - public sealed class ProvidesDescriptorAttribute(string descriptorAccessorName, bool descriptorIsOrdered = true) : Attribute + public sealed class DescriptorProviderAttribute(string descriptorAccessorName, bool descriptorIsOrdered = true) : Attribute { public string DescriptorAccessorName { get; } = descriptorAccessorName; public bool DescriptorIsOrdered { get; } = descriptorIsOrdered; diff --git a/PlugHub.Shared/Interfaces/Plugins/IPluginAppConfig.cs b/PlugHub.Shared/Interfaces/Plugins/IPluginAppConfig.cs index 443e14a..bb26a65 100644 --- a/PlugHub.Shared/Interfaces/Plugins/IPluginAppConfig.cs +++ b/PlugHub.Shared/Interfaces/Plugins/IPluginAppConfig.cs @@ -32,7 +32,7 @@ public record PluginAppConfigDescriptor( /// Interface for plugins that supply branding assets, configuration and/or metadata. /// Provides descriptors for visual, branding, and identity-related resources included with the plugin. /// - [ProvidesDescriptor("GetAppConfigDescriptors", false)] + [DescriptorProvider("GetAppConfigDescriptors", false)] public interface IPluginAppConfig : IPlugin { /// diff --git a/PlugHub.Shared/Interfaces/Plugins/IPluginConfiguration.cs b/PlugHub.Shared/Interfaces/Plugins/IPluginConfiguration.cs index ae63752..037ea9a 100644 --- a/PlugHub.Shared/Interfaces/Plugins/IPluginConfiguration.cs +++ b/PlugHub.Shared/Interfaces/Plugins/IPluginConfiguration.cs @@ -34,7 +34,7 @@ public record PluginConfigurationDescriptor( /// Interface for plugins that register configuration options. /// Provides metadata describing configuration settings. /// - [ProvidesDescriptor("GetConfigurationDescriptors", false)] + [DescriptorProvider("GetConfigurationDescriptors", false)] public interface IPluginConfiguration : IPlugin { /// diff --git a/PlugHub.Shared/Interfaces/Plugins/IPluginDependencyInjection.cs b/PlugHub.Shared/Interfaces/Plugins/IPluginDependencyInjection.cs index 30460a9..ddcfc68 100644 --- a/PlugHub.Shared/Interfaces/Plugins/IPluginDependencyInjection.cs +++ b/PlugHub.Shared/Interfaces/Plugins/IPluginDependencyInjection.cs @@ -38,7 +38,7 @@ public record PluginInjectorDescriptor( /// Interface for plugins that participate in dependency injection. /// Provides descriptors for services the plugin injects into the host or other plugins. /// - [ProvidesDescriptor("GetInjectionDescriptors", false)] + [DescriptorProvider("GetInjectionDescriptors", false)] public interface IPluginDependencyInjection : IPlugin { /// diff --git a/PlugHub.Shared/Utility/Atomic.cs b/PlugHub.Shared/Utility/Atomic.cs index 29409ec..7d55146 100644 --- a/PlugHub.Shared/Utility/Atomic.cs +++ b/PlugHub.Shared/Utility/Atomic.cs @@ -31,9 +31,7 @@ public static void Write(string destinationPath, ReadOnlySpan data) bool directoryExists = Directory.Exists(dir); if (!directoryExists) - { Directory.CreateDirectory(dir); - } string tempPath = Path.Combine(dir, Guid.NewGuid().ToString("N") + ".tmp"); File.WriteAllBytes(tempPath, data.ToArray()); @@ -61,7 +59,6 @@ public static async Task WriteAsync(string destinationPath, ReadOnlyMemory try { - // Stage 1: Write to temporary file with optimal settings await using (FileStream fs = new( tempPath, FileMode.Create, @@ -73,17 +70,12 @@ public static async Task WriteAsync(string destinationPath, ReadOnlyMemory await fs.WriteAsync(bytes, cancellationToken); } - // Stage 2: Atomically move to final destination bool destinationExists = File.Exists(destinationPath); if (destinationExists) - { File.Replace(tempPath, destinationPath, null, ignoreMetadataErrors: true); - } else - { File.Move(tempPath, destinationPath); - } return; } @@ -99,7 +91,6 @@ public static async Task WriteAsync(string destinationPath, ReadOnlyMemory cancellationToken.ThrowIfCancellationRequested(); } - // Stage 3: Throw exception for max retries exceeded throw new IOException($"Unable to write '{destinationPath}' after {maxRetries} attempts."); } @@ -111,9 +102,7 @@ private static void EnsureDirectoryExists(string path) string? dir = Path.GetDirectoryName(path); if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir)) - { Directory.CreateDirectory(dir); - } } private static void CleanupTempFile(string tempPath) @@ -121,15 +110,11 @@ private static void CleanupTempFile(string tempPath) try { bool tempFileExists = File.Exists(tempPath); + if (tempFileExists) - { File.Delete(tempPath); - } - } - catch - { - // Cleanup failures are non-critical - ignored intentionally } + catch { /* Nothing to see here */ } } #endregion diff --git a/PlugHub/Services/Plugins/PluginRegistrar.cs b/PlugHub/Services/Plugins/PluginRegistrar.cs index 2f45f6c..b042d0f 100644 --- a/PlugHub/Services/Plugins/PluginRegistrar.cs +++ b/PlugHub/Services/Plugins/PluginRegistrar.cs @@ -104,12 +104,12 @@ public List GetDescriptorsForInterface(Type pluginInterfaceTyp continue; } - ProvidesDescriptorAttribute? attr = null; + DescriptorProviderAttribute? attr = null; Type[] allInterfaces = [pluginInterface.InterfaceType, .. pluginInterface.InterfaceType.GetInterfaces()]; foreach (Type it in allInterfaces) { - attr = it.GetCustomAttribute(inherit: false); + attr = it.GetCustomAttribute(inherit: false); if (attr != null) break; } diff --git a/PlugHub/Services/Plugins/PluginService.cs b/PlugHub/Services/Plugins/PluginService.cs index 1cf3b39..6b94755 100644 --- a/PlugHub/Services/Plugins/PluginService.cs +++ b/PlugHub/Services/Plugins/PluginService.cs @@ -210,13 +210,13 @@ private List FilterInterfaceTypes(List pluginInterfaceTypes) foreach (Type interfaceType in pluginInterfaceTypes) { - ProvidesDescriptorAttribute? attr = null; + DescriptorProviderAttribute? attr = null; Type[] allInterfaces = [interfaceType, .. interfaceType.GetInterfaces()]; foreach (Type it in allInterfaces) { - attr = it.GetCustomAttribute(inherit: false); + attr = it.GetCustomAttribute(inherit: false); if (attr != null) break; }