Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion PlugHub.Shared/Interfaces/Plugins/IPluginAppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
[ProvidesDescriptor("GetAppConfigDescriptors", false)]
[DescriptorProvider("GetAppConfigDescriptors", false)]
public interface IPluginAppConfig : IPlugin
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion PlugHub.Shared/Interfaces/Plugins/IPluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public record PluginConfigurationDescriptor(
/// Interface for plugins that register configuration options.
/// Provides metadata describing configuration settings.
/// </summary>
[ProvidesDescriptor("GetConfigurationDescriptors", false)]
[DescriptorProvider("GetConfigurationDescriptors", false)]
public interface IPluginConfiguration : IPlugin
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
[ProvidesDescriptor("GetInjectionDescriptors", false)]
[DescriptorProvider("GetInjectionDescriptors", false)]
public interface IPluginDependencyInjection : IPlugin
{
/// <summary>
Expand Down
19 changes: 2 additions & 17 deletions PlugHub.Shared/Utility/Atomic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public static void Write(string destinationPath, ReadOnlySpan<byte> 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());
Expand Down Expand Up @@ -61,7 +59,6 @@ public static async Task WriteAsync(string destinationPath, ReadOnlyMemory<byte>

try
{
// Stage 1: Write to temporary file with optimal settings
await using (FileStream fs = new(
tempPath,
FileMode.Create,
Expand All @@ -73,17 +70,12 @@ public static async Task WriteAsync(string destinationPath, ReadOnlyMemory<byte>
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;
}
Expand All @@ -99,7 +91,6 @@ public static async Task WriteAsync(string destinationPath, ReadOnlyMemory<byte>
cancellationToken.ThrowIfCancellationRequested();
}

// Stage 3: Throw exception for max retries exceeded
throw new IOException($"Unable to write '{destinationPath}' after {maxRetries} attempts.");
}

Expand All @@ -111,25 +102,19 @@ 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)
{
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
Expand Down
4 changes: 2 additions & 2 deletions PlugHub/Services/Plugins/PluginRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ public List<PluginDescriptor> 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<ProvidesDescriptorAttribute>(inherit: false);
attr = it.GetCustomAttribute<DescriptorProviderAttribute>(inherit: false);
if (attr != null)
break;
}
Expand Down
4 changes: 2 additions & 2 deletions PlugHub/Services/Plugins/PluginService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ private List<Type> FilterInterfaceTypes(List<Type> 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<ProvidesDescriptorAttribute>(inherit: false);
attr = it.GetCustomAttribute<DescriptorProviderAttribute>(inherit: false);
if (attr != null)
break;
}
Expand Down
Loading