@@ -77,6 +77,15 @@ std::filesystem::path index_pkgs_dir(const std::filesystem::path& indexDir) {
7777 return indexDir / " pkgs" ;
7878}
7979
80+ // AN INDEX IS PRESENT WHEN ITS PACKAGES ARE. A reader that finds none reports no local package
81+ // index (`index_status_for`), and a refresh beside another process waits for it
82+ // (`every_index_present`): one judgement, so that a directory another process has made and not
83+ // yet filled is absent to both (mcpp#927).
84+ bool index_present (const std::filesystem::path& indexDir) {
85+ std::error_code ec;
86+ return std::filesystem::exists (index_pkgs_dir (indexDir), ec) && !ec;
87+ }
88+
8089std::filesystem::path index_refresh_marker (const std::filesystem::path& indexDir) {
8190 return indexDir / " .mcpp-index-updated" ;
8291}
@@ -119,7 +128,7 @@ bool official_index_cache_matches_package_file(const Env& env,
119128}
120129
121130void mark_index_refreshed (const std::filesystem::path& indexDir) {
122- if (!std::filesystem::exists ( index_pkgs_dir ( indexDir) )) return ;
131+ if (!index_present ( indexDir)) return ;
123132 std::error_code ec;
124133 std::filesystem::create_directories (indexDir, ec);
125134 auto marker = index_refresh_marker (indexDir);
@@ -145,7 +154,7 @@ void mark_known_indexes_refreshed(const Env& env) {
145154
146155bool is_index_dir_fresh (const std::filesystem::path& indexDir, std::int64_t ttlSeconds) {
147156 std::error_code ec;
148- if (!std::filesystem::exists ( index_pkgs_dir ( indexDir) )) return false ;
157+ if (!index_present ( indexDir)) return false ;
149158
150159 auto marker = index_refresh_marker (indexDir);
151160 if (!std::filesystem::exists (marker)) return false ;
@@ -197,11 +206,9 @@ std::optional<std::string> read_index_revision(const std::filesystem::path& inde
197206
198207IndexStatus index_status_for (const std::filesystem::path& indexDir,
199208 std::int64_t ttlSeconds) {
200- std::error_code ec;
201- bool present = std::filesystem::exists (index_pkgs_dir (indexDir), ec) && !ec;
202209 return IndexStatus{
203210 .dir = indexDir,
204- .present = present ,
211+ .present = index_present (indexDir) ,
205212 .fresh = is_index_dir_fresh (indexDir, ttlSeconds),
206213 .ageSeconds = index_age_seconds (indexDir),
207214 .rev = read_index_revision (indexDir),
@@ -2198,6 +2205,13 @@ int update_index(const Env& env, bool quiet) {
21982205}
21992206
22002207namespace {
2208+ // Every index a reader of this home reads, as it judges one: the provider's own and each declared.
2209+ bool every_index_present (const Env& env) {
2210+ return index_present (official_index_dir (env))
2211+ && std::ranges::all_of (paths::declared_indices (env),
2212+ [](const auto & d) { return index_present (d.dir ); });
2213+ }
2214+
22012215int update_index_unguarded (const Env& env, bool quiet) {
22022216 // Offline is absolute: no caller gets to reach the network by going around
22032217 // the decision layer. Reported as success so a build that can still resolve
@@ -2226,11 +2240,12 @@ int update_index_unguarded(const Env& env, bool quiet) {
22262240 // was still fetching, or exchanging on a volume without an atomic
22272241 // exchange, and reported "no local package index" for a home that had
22282242 // one a moment later. Such a reader waits for the refresh it skipped;
2229- // one with an index skips as before.
2230- bool absent = false ;
2231- for (const auto & d : paths::declared_indices (env))
2232- if (!std::filesystem::exists (d.dir , lockEc)) absent = true ;
2233- if (!absent) {
2243+ // one with every index skips as before. Every index is the provider's
2244+ // own (xim) and each the home declares, judged as a reader judges one
2245+ // (`index_present`): the declared directories alone, by existence,
2246+ // let a reader skip beside a first fetch of xim, and beside a declared
2247+ // directory made and not yet filled.
2248+ if (every_index_present (env)) {
22342249 mcpp::log::verbose (" index" ,
22352250 " another process is refreshing the index — skipping this one" );
22362251 return 0 ;
0 commit comments