refactor(agent): remove obsolete compatibility paths
This commit is contained in:
@@ -37,26 +37,10 @@ public sealed record RemoteNodeConfiguration
|
||||
Audit = (Audit ?? []).TakeLast(1000).ToArray()
|
||||
};
|
||||
}
|
||||
|
||||
public RemoteNodeConfiguration WithAudit(string action)
|
||||
{
|
||||
RemoteAgentOptions.ValidateIdentifier(action, "action", 120);
|
||||
return this with
|
||||
{
|
||||
Audit = (Audit ?? []).Append(new RemoteConfigurationAuditEntry
|
||||
{
|
||||
At = DateTimeOffset.UtcNow,
|
||||
Action = action,
|
||||
ConfigVersion = Reporting?.ConfigVersion ?? 0
|
||||
}).TakeLast(1000).ToArray()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class RemoteNodeConfigurationStore
|
||||
{
|
||||
private static readonly SemaphoreSlim Gate = new(1, 1);
|
||||
|
||||
public static async Task<RemoteNodeConfiguration> LoadAsync(string path, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
@@ -82,40 +66,4 @@ public static class RemoteNodeConfigurationStore
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task SaveAsync(string path, RemoteNodeConfiguration configuration, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var normalized = configuration.NormalizeAndValidate();
|
||||
var destination = Path.GetFullPath(path);
|
||||
var directory = Path.GetDirectoryName(destination) ?? AppContext.BaseDirectory;
|
||||
Directory.CreateDirectory(directory);
|
||||
await Gate.WaitAsync(cancellationToken);
|
||||
try
|
||||
{
|
||||
var temporary = destination + ".tmp-" + Guid.NewGuid().ToString("N");
|
||||
try
|
||||
{
|
||||
await using (var stream = new FileStream(temporary, FileMode.CreateNew, FileAccess.Write, FileShare.None, 4096, FileOptions.WriteThrough))
|
||||
{
|
||||
await JsonSerializer.SerializeAsync(stream, normalized, RemoteJson.Options, cancellationToken);
|
||||
await stream.FlushAsync(cancellationToken);
|
||||
}
|
||||
if (!OperatingSystem.IsWindows())
|
||||
{
|
||||
try { File.SetUnixFileMode(temporary, UnixFileMode.UserRead | UnixFileMode.UserWrite); }
|
||||
catch (PlatformNotSupportedException) { }
|
||||
}
|
||||
if (OperatingSystem.IsWindows() && File.Exists(destination)) File.Replace(temporary, destination, null);
|
||||
else File.Move(temporary, destination, true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (File.Exists(temporary)) File.Delete(temporary);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Gate.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user