From 628ff3564bf1f28f8795c1d89ffb0481671f1d5f Mon Sep 17 00:00:00 2001 From: JohnConnorNPC <128232619+JohnConnorNPC@users.noreply.github.com> Date: Sun, 29 Nov 2026 18:09:51 +1000 Subject: [PATCH] startup: leave a cache listing with no entries to the disk FindFirstFileExW on "\*" returns "." and ".." for an empty directory, so ERROR_FILE_NOT_FOUND only comes from a directory with no entry at all, such as an empty volume root. No test reached the branch that treated it as an empty listing: with it removed, startup_cache_index_check (f) still passed under Wine. Drop it, so that every listing failure leaves the index unknown and lookups use the disk, as before the index. Fix the (a) lookup count in the check's header comment: 512 + 3 = 515. --- src/startup_stubs/cache_index.h | 13 ++++++++----- tests/startup_cache_index_check.cpp | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/startup_stubs/cache_index.h b/src/startup_stubs/cache_index.h index a8bd672460..9c4335c12a 100644 --- a/src/startup_stubs/cache_index.h +++ b/src/startup_stubs/cache_index.h @@ -9,10 +9,12 @@ // // CacheDirectoryIndex lists one directory once, at its first lookup (std::call_once; FindFirstFileExW on // "\*", files only, so names in subdirectories are not indexed). A lookup answers present, absent or -// unknown. unknown means "look on disk": the listing failed (any error but ERROR_FILE_NOT_FOUND, including a -// missing directory), or the lookup names a directory other than the listed one. A file that another process -// creates after the listing reads absent until the next process starts. add() records the caller's own writes, and -// count_contradiction() counts a write that found a file the index had reported absent. +// unknown. unknown means "look on disk": the listing failed (any error, including a missing directory), or the +// lookup names a directory other than the listed one. An empty directory lists empty, through its "." and ".." +// entries; a directory with no entry at all, such as an empty volume root, fails with ERROR_FILE_NOT_FOUND and so +// uses the disk, as the stand-in did before the index. A file that another process creates after the listing reads +// absent until the next process starts. add() records the caller's own writes, and count_contradiction() counts a +// write that found a file the index had reported absent. #pragma once #include @@ -159,8 +161,9 @@ class CacheDirectoryIndex { const HANDLE find = FindFirstFileExW(mask.c_str(), FindExInfoBasic, &found, FindExSearchNameMatch, nullptr, FIND_FIRST_EX_LARGE_FETCH); if (find == INVALID_HANDLE_VALUE) { + // Every failure leaves the index unusable, ERROR_FILE_NOT_FOUND (no entry at all, not even "." or + // "..", as in an empty volume root) included: its lookups use the disk. error = GetLastError(); - if (error == ERROR_FILE_NOT_FOUND) error = ERROR_SUCCESS; // no entry at all: an empty listing } else { try { do { diff --git a/tests/startup_cache_index_check.cpp b/tests/startup_cache_index_check.cpp index c64a804d1e..c5071f0a61 100644 --- a/tests/startup_cache_index_check.cpp +++ b/tests/startup_cache_index_check.cpp @@ -1,7 +1,7 @@ // Checks src/startup_stubs/cache_index.h without a device. prepare_native_mesh57 asks the index before it opens // .mesh57-state, and opens the file only for present or unknown. The cache directory holds 2000 other // cache files, names that look like profiles, a subdirectory and a directory with a profile's name. -// (a) 514 lookups of missing profiles probe the disk 0 times; (b) present profiles, any ASCII case, are read; +// (a) 515 lookups of missing profiles probe the disk 0 times; (b) present profiles, any ASCII case, are read; // (c) one listing of the top-level files only; (d) other directories and subdirectories: unknown; // (e) add() and the contradiction counter; (f) an empty directory lists empty, a missing one // is unknown; (g) concurrent first lookups list once and agree; (h) the name hash and the sorted set.