From 1d7f7e6423763240460632f3b388a092f8ac8c43 Mon Sep 17 00:00:00 2001 From: Dillard Blom Date: Mon, 19 Oct 2026 01:52:58 +0200 Subject: [PATCH] Read ahead: resolve paths before opening connections; a failing readAhead() leaves no spool folder --- lib/Backend/StorageBackend.php | 3 ++- lib/Repository/Repository.php | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Backend/StorageBackend.php b/lib/Backend/StorageBackend.php index 8d59e6c..24ee719 100644 --- a/lib/Backend/StorageBackend.php +++ b/lib/Backend/StorageBackend.php @@ -257,6 +257,8 @@ final class StorageBackend implements IBackend, IReadsAhead { if (!$this->sftpReads || $reconnect === null || $ranges === []) { return null; } + // before any connection is opened: an invalid path throws + $abs = array_map(fn (array $r): array => [$this->abs($r[0]), $r[1], $r[2]], $ranges); $storages = []; $connections = []; $root = ''; @@ -277,7 +279,6 @@ final class StorageBackend implements IBackend, IReadsAhead { if ($connections === []) { return null; } - $abs = array_map(fn (array $r): array => [$this->abs($r[0]), $r[1], $r[2]], $ranges); return (static function () use ($storages, $connections, $root, $abs, $spool): \Generator { // the storages hold their connections: kept until the fetcher is done try { diff --git a/lib/Repository/Repository.php b/lib/Repository/Repository.php index ad71021..284a300 100644 --- a/lib/Repository/Repository.php +++ b/lib/Repository/Repository.php @@ -254,7 +254,11 @@ final class Repository { if (count($plan->ranges()) < 2 || (!is_dir($plan->spool) && !@mkdir($plan->spool, 0700, true))) { return null; } - $streams = $this->backend->readAhead($plan->ranges(), $plan->spool); + try { + $streams = $this->backend->readAhead($plan->ranges(), $plan->spool); + } catch (\Throwable) { + $streams = null; // the usual reads report what is wrong + } if ($streams === null) { @rmdir($plan->spool); return null;