From 8eb6c4c0334d409d444e3e49dc0e15d1e81f0bb1 Mon Sep 17 00:00:00 2001 From: Dillard Blom Date: Wed, 21 Oct 2026 20:56:45 +0200 Subject: [PATCH] Index: check known index files spread over the list --- lib/Repository/BlobIndex.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Repository/BlobIndex.php b/lib/Repository/BlobIndex.php index a14dd2c..6d7e7e2 100644 --- a/lib/Repository/BlobIndex.php +++ b/lib/Repository/BlobIndex.php @@ -234,9 +234,10 @@ final class BlobIndex { * pack ids) is usually a connection that failed quietly; taken as is, it would empty the * index and the cache, make a check report every blob missing, or make a cleanup wipe the * cache. So the connection is checked (the repository's config must be there) and the folder - * listed once more. Empty again, a few of the known index files are looked up one by one: - * only when they are gone too is the repository really empty (another server removed its - * last snapshot and cleaned up). + * listed once more. Empty again, three of the known index files are looked up one by one: + * only when they are gone too is the repository taken as empty (another server removed its + * last snapshot and cleaned up). Even when that is wrong, nothing on the location is lost: + * only this index and the cache are empty until the next load. * * @param list $known * @return list @@ -254,7 +255,10 @@ final class BlobIndex { if ($paths !== []) { return $paths; } - foreach (array_slice($known, 0, 3) as $packId) { + // spread over the list: first, middle and last (another server's cleanup removes packs + // here and there, not in this order) + $n = count($known); + foreach (array_unique([$known[0], $known[intdiv($n, 2)], $known[$n - 1]]) as $packId) { if ($this->backend->exists('index/' . $packId)) { throw new BackendException('The location listed no index files, while index/' . $packId . ' is there: not trusting that listing'); }