diff --git a/ProxyForge/Cache/SourceIdentity.cs b/ProxyForge/Cache/SourceIdentity.cs new file mode 100644 index 0000000..1448396 --- /dev/null +++ b/ProxyForge/Cache/SourceIdentity.cs @@ -0,0 +1,30 @@ +using System.IO; + +namespace ProxyForge.Cache; + +internal readonly record struct SourceIdentity(string Path, long Length, long WriteTimeTicks) +{ + public static SourceIdentity? Of(string path) + { + string fullPath; + try + { + fullPath = System.IO.Path.GetFullPath(path); + } + catch (Exception exception) when (exception is ArgumentException or PathTooLongException or NotSupportedException) + { + return null; + } + + var file = new FileInfo(fullPath); + if (!file.Exists) + return null; + + return new SourceIdentity(fullPath, file.Length, file.LastWriteTimeUtc.Ticks); + } + + public bool Matches(string path, long length, long writeTimeTicks) + => Length == length + && WriteTimeTicks == writeTimeTicks + && string.Equals(Path, path, StringComparison.OrdinalIgnoreCase); +}