Adhere to ExcludedSubpaths while scanning directory for change

This commit is contained in:
Simon Lübeß
2026-04-13 20:05:41 +02:00
parent aad44dd835
commit 6bec99ab06
3 changed files with 37 additions and 18 deletions
+35 -16
View File
@@ -79,22 +79,7 @@ abstract class Module
// Since we don't save anything directory specific in the has, we can skip this check if we already know that we are going to rebuild.
if (!needsRebuild)
{
foreach (FileSystemInfo dirEntry in dirInfo.EnumerateFileSystemInfos("**",
enumerationOptions: new EnumerationOptions()
{ MatchType = MatchType.Win32, RecurseSubdirectories = source.Recursive }))
{
//string relativePath = Path.GetRelativePath(dirInfo.FullName, dirEntry.FullName);
//if (source.ExcludedDirectories.Contains(relativePath, StringComparer.OrdinalIgnoreCase))
// continue;
Console.WriteLine("Checking entry: " + dirEntry.FullName);
if (dirEntry.LastWriteTimeUtc > cacheInfo.LastSuccessfulBuild)
{
Console.WriteLine("Needs rebuild");
needsRebuild = true;
break;
}
}
needsRebuild = DirectoryNeedsRebuild(cacheInfo, dirInfo, source, needsRebuild);
}
// We really just need any timestamp, to know that the directory existed at some point.
@@ -152,6 +137,40 @@ abstract class Module
return needsRebuild;
}
private static bool DirectoryNeedsRebuild(ModuleInfo cacheInfo, DirectoryInfo dirInfo, WatchedSource source,
bool needsRebuild)
{
Stack<DirectoryInfo> directoriesToCheck = new ();
directoriesToCheck.Push(dirInfo);
while (directoriesToCheck.Count > 0)
{
DirectoryInfo directory = directoriesToCheck.Pop();
foreach (FileSystemInfo dirEntry in directory.EnumerateFileSystemInfos())
{
string relativePath = Path.GetRelativePath(dirInfo.FullName, dirEntry.FullName);
if (source.ExcludedSubpaths.Contains(relativePath, StringComparer.OrdinalIgnoreCase))
continue;
if (dirEntry.Attributes.HasFlag(FileAttributes.Directory))
{
directoriesToCheck.Push(new DirectoryInfo(dirEntry.FullName));
}
Console.WriteLine("Checking entry: " + dirEntry.FullName);
if (dirEntry.LastWriteTimeUtc > cacheInfo.LastSuccessfulBuild)
{
Console.WriteLine("Needs rebuild");
needsRebuild = true;
break;
}
}
}
return needsRebuild;
}
private static string ComputeFileHash(string filePath)
{
using var stream = File.OpenRead(filePath);
+1 -1
View File
@@ -38,7 +38,7 @@ class ScriptCoreModule : Module
sources.Add(new WatchedSource("ScriptCore/", WatchMode.Metadata)
{
Recursive = true,
ExcludedDirectories =
ExcludedSubpaths =
[
"bin",
"obj"
+1 -1
View File
@@ -27,7 +27,7 @@ internal record WatchedSource(string Path, WatchMode Mode)
/// <summary>
/// Only if Path points to a directory, a list of subdirectories to exclude from change checking.
/// </summary>
public List<string> ExcludedDirectories { get; init; } = new();
public List<string> ExcludedSubpaths { get; init; } = new();
/// <summary>
/// Only if Path points to a directory, whether to check for changes in subdirectories as well.
/// </summary>