From 0f68e04cd8f9df0898099861f514badb508e48c9 Mon Sep 17 00:00:00 2001 From: routersys Date: Sun, 13 Sep 2026 10:55:14 +0900 Subject: [PATCH] =?UTF-8?q?=E5=85=83=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=81=AE=E5=90=8C=E4=B8=80=E6=80=A7=E3=81=AE=E5=9E=8B=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProxyForge/Cache/SourceIdentity.cs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 ProxyForge/Cache/SourceIdentity.cs 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); +}