元ファイルの同一性を等価性として定義する
このコミットが含まれているのは:
4ファイル変更
+21
-15
検索条件に一致するファイルはありません
@@ -77,6 +77,19 @@ public sealed class ProxyCacheTests : IDisposable
|
||||
Assert.Equal(File.GetLastWriteTimeUtc(path).Ticks, identity.WriteTimeTicks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdentitiesAreEqualRegardlessOfThePathCase()
|
||||
{
|
||||
var identity = new SourceIdentity(@"C:\Videos\Source.mp4", 123L, 456L);
|
||||
var upper = identity with { Path = identity.Path.ToUpperInvariant() };
|
||||
|
||||
Assert.Equal(identity, upper);
|
||||
Assert.Equal(identity.GetHashCode(), upper.GetHashCode());
|
||||
Assert.NotEqual(identity, identity with { Length = 124L });
|
||||
Assert.NotEqual(identity, identity with { WriteTimeTicks = 457L });
|
||||
Assert.NotEqual(identity, identity with { Path = @"C:\Videos\Other.mp4" });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnEmptyCacheFindsNothing()
|
||||
{
|
||||
|
||||
@@ -27,4 +27,8 @@ internal readonly record struct SourceIdentity(string Path, long Length, long Wr
|
||||
=> Length == length
|
||||
&& WriteTimeTicks == writeTimeTicks
|
||||
&& string.Equals(Path, path, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
public bool Equals(SourceIdentity other) => Matches(other.Path, other.Length, other.WriteTimeTicks);
|
||||
|
||||
public override int GetHashCode() => HashCode.Combine(StringComparer.OrdinalIgnoreCase.GetHashCode(Path), Length, WriteTimeTicks);
|
||||
}
|
||||
@@ -23,25 +23,14 @@ internal sealed class ProxyGenerationQueue(
|
||||
|
||||
readonly record struct Key(SourceIdentity Source, int Scale);
|
||||
|
||||
sealed class KeyComparer : IEqualityComparer<Key>
|
||||
{
|
||||
public static KeyComparer Instance { get; } = new();
|
||||
|
||||
public bool Equals(Key x, Key y)
|
||||
=> x.Scale == y.Scale && x.Source.Matches(y.Source.Path, y.Source.Length, y.Source.WriteTimeTicks);
|
||||
|
||||
public int GetHashCode(Key key)
|
||||
=> HashCode.Combine(StringComparer.OrdinalIgnoreCase.GetHashCode(key.Source.Path), key.Source.Length, key.Source.WriteTimeTicks, key.Scale);
|
||||
}
|
||||
|
||||
sealed class ItemProgress(ProxyGenerationItem item, Action<Action> onUi) : IProgress<double>
|
||||
{
|
||||
public void Report(double value) => onUi(() => item.Progress = value);
|
||||
}
|
||||
|
||||
readonly Lock gate = new();
|
||||
readonly Dictionary<Key, (CancellationTokenSource Cancellation, Task Task)> pending = new(KeyComparer.Instance);
|
||||
readonly HashSet<Key> failures = new(KeyComparer.Instance);
|
||||
readonly Dictionary<Key, (CancellationTokenSource Cancellation, Task Task)> pending = [];
|
||||
readonly HashSet<Key> failures = [];
|
||||
readonly SemaphoreSlim slot = new(1, 1);
|
||||
|
||||
public static ProxyGenerationQueue Shared { get; } = new(
|
||||
@@ -212,7 +201,7 @@ internal sealed class ProxyGenerationQueue(
|
||||
{
|
||||
result = await encode(request, new ItemProgress(item, onUi), token).ConfigureAwait(false);
|
||||
var latest = SourceIdentity.Of(key.Source.Path);
|
||||
if (latest is null || !latest.Value.Matches(key.Source.Path, key.Source.Length, key.Source.WriteTimeTicks))
|
||||
if (latest != key.Source)
|
||||
throw new ProxyEncodeException(ProxyEncodeFailure.SourceChanged, "The source file changed while the proxy was being generated.");
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -44,7 +44,7 @@ internal sealed class ProxyUpgradeLoader : IDisposable
|
||||
|
||||
void OnCompleted(SourceIdentity completedSource, int completedScale, ProxyCacheEntry entry)
|
||||
{
|
||||
if (completedScale == scale && completedSource.Matches(source.Path, source.Length, source.WriteTimeTicks))
|
||||
if (completedScale == scale && completedSource == source)
|
||||
Begin(entry);
|
||||
}
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする