fix: parse project rosters with legacy-compatible semantics
This commit is contained in:
@@ -59,3 +59,30 @@ public static class LegacyNetworkConfiguration
|
||||
private static string Hash(string path) { using var stream = File.OpenRead(path); return Convert.ToHexString(SHA256.HashData(stream)); }
|
||||
private static string Fingerprint(string endpoint, string hash) => Convert.ToHexString(SHA256.HashData(System.Text.Encoding.UTF8.GetBytes(endpoint + "|" + hash)));
|
||||
}
|
||||
|
||||
public static class LegacyReadOnlySnapshots
|
||||
{
|
||||
public static LegacySettingsSnapshot Acquire(string source, string localRoot, string role)
|
||||
{
|
||||
if (!Path.IsPathFullyQualified(source) || !source.StartsWith(@"\\", StringComparison.Ordinal) || source.Contains('?') || source.Contains('*') || !File.Exists(source) || File.GetAttributes(source).HasFlag(FileAttributes.ReparsePoint)) throw new InvalidOperationException("READONLY_SNAPSHOT_SOURCE_INVALID");
|
||||
var before = new FileInfo(source);
|
||||
var beforeHash = Hash(source);
|
||||
var directory = Path.Combine(Path.GetFullPath(localRoot), "configuration-snapshots", role);
|
||||
Directory.CreateDirectory(directory);
|
||||
var temporary = Path.Combine(directory, Guid.NewGuid().ToString("N") + ".tmp");
|
||||
File.Copy(source, temporary, false);
|
||||
var copiedHash = Hash(temporary);
|
||||
var after = new FileInfo(source);
|
||||
var afterHash = Hash(source);
|
||||
if (before.Length != after.Length || before.LastWriteTimeUtc != after.LastWriteTimeUtc || beforeHash != afterHash || copiedHash != afterHash)
|
||||
{
|
||||
File.Delete(temporary);
|
||||
throw new InvalidOperationException("READONLY_SNAPSHOT_SOURCE_CHANGED");
|
||||
}
|
||||
var final = Path.Combine(directory, copiedHash + ".xml");
|
||||
if (File.Exists(final)) File.Delete(temporary); else File.Move(temporary, final);
|
||||
return new(source, Convert.ToHexString(SHA256.HashData(System.Text.Encoding.UTF8.GetBytes(role + "|" + source + "|" + copiedHash))), copiedHash, before.Length, new DateTimeOffset(before.LastWriteTimeUtc), DateTimeOffset.UtcNow, final, false);
|
||||
}
|
||||
|
||||
private static string Hash(string path) { using var stream = File.OpenRead(path); return Convert.ToHexString(SHA256.HashData(stream)); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user