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.