From d68999dfb77e2eadf0c03e254479b774cb4047d3 Mon Sep 17 00:00:00 2001 From: maj00r Date: Tue, 3 Nov 2026 21:51:56 +0100 Subject: [PATCH] Look at each source file of a scenery once The watch of scenery files asked three times per file, whether it is there, its time and its size, every two seconds for every source of every scenery. One look gives all three. --- StarterNG.Tests/Fakes/InMemoryFileSystem.cs | 3 +++ StarterNG/Application/Abstractions/IFileSystem.cs | 3 +++ StarterNG/Domain/Sceneries/FileStamp.cs | 4 +--- StarterNG/Infrastructure/Adapters/PhysicalFileSystem.cs | 6 ++++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/StarterNG.Tests/Fakes/InMemoryFileSystem.cs b/StarterNG.Tests/Fakes/InMemoryFileSystem.cs index e95f021..79108cb 100644 --- a/StarterNG.Tests/Fakes/InMemoryFileSystem.cs +++ b/StarterNG.Tests/Fakes/InMemoryFileSystem.cs @@ -200,6 +200,9 @@ public sealed class InMemoryFileSystem : IFileSystem /// Files added through carry the execute bit. public long GetFileSize(string path) => Bytes(path).LongLength; + public (DateTime LastWriteUtc, long Size)? LastWriteAndSize(string path) => + FileExists(path) ? (GetLastWriteTimeUtc(path), GetFileSize(path)) : null; + public bool IsExecutable(string path) => _executable.Contains(Normalize(path)); public InMemoryFileSystem WithExecutable(string path, string contents = "\u007fELF") diff --git a/StarterNG/Application/Abstractions/IFileSystem.cs b/StarterNG/Application/Abstractions/IFileSystem.cs index 66e8ca3..e04f862 100644 --- a/StarterNG/Application/Abstractions/IFileSystem.cs +++ b/StarterNG/Application/Abstractions/IFileSystem.cs @@ -55,6 +55,9 @@ public interface IFileSystem long GetFileSize(string path); + /// A file's time and size in one look; null when there is no file. + (DateTime LastWriteUtc, long Size)? LastWriteAndSize(string path); + bool IsExecutable(string path); /// Where the symbolic link at points, or null for anything else. diff --git a/StarterNG/Domain/Sceneries/FileStamp.cs b/StarterNG/Domain/Sceneries/FileStamp.cs index 674bca0..f892461 100644 --- a/StarterNG/Domain/Sceneries/FileStamp.cs +++ b/StarterNG/Domain/Sceneries/FileStamp.cs @@ -11,9 +11,7 @@ public readonly record struct FileStamp(DateTime LastWriteUtc, long Size) { try { - return files.FileExists(path) - ? new FileStamp(files.GetLastWriteTimeUtc(path), files.GetFileSize(path)) - : null; + return files.LastWriteAndSize(path) is { } stat ? new FileStamp(stat.LastWriteUtc, stat.Size) : null; } catch (Exception) { diff --git a/StarterNG/Infrastructure/Adapters/PhysicalFileSystem.cs b/StarterNG/Infrastructure/Adapters/PhysicalFileSystem.cs index db9350d..15ae4ee 100644 --- a/StarterNG/Infrastructure/Adapters/PhysicalFileSystem.cs +++ b/StarterNG/Infrastructure/Adapters/PhysicalFileSystem.cs @@ -110,6 +110,12 @@ public sealed class PhysicalFileSystem : IFileSystem public long GetFileSize(string path) => new FileInfo(path).Length; + public (DateTime LastWriteUtc, long Size)? LastWriteAndSize(string path) + { + var info = new FileInfo(path); + return info.Exists ? (info.LastWriteTimeUtc, info.Length) : null; + } + public bool IsExecutable(string path) { if (OperatingSystem.IsWindows())