Skip to content

Commit 2221c69

Browse files
icewind1991backportbot[bot]
authored andcommitted
fix: make failed availability check apply in the same request
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent f50d9d2 commit 2221c69

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

lib/private/Files/Storage/Wrapper/Availability.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Availability extends Wrapper {
2222

2323
/** @var IConfig */
2424
protected $config;
25+
protected ?bool $available = null;
2526

2627
public function __construct(array $parameters) {
2728
$this->config = $parameters['config'] ?? \OCP\Server::get(IConfig::class);
@@ -54,11 +55,14 @@ private function updateAvailability(): bool {
5455
}
5556

5657
private function isAvailable(): bool {
57-
$availability = $this->getAvailability();
58-
if (self::shouldRecheck($availability)) {
59-
return $this->updateAvailability();
58+
if (is_null($this->available)) {
59+
$availability = $this->getAvailability();
60+
if (self::shouldRecheck($availability)) {
61+
return $this->updateAvailability();
62+
}
63+
$this->available = $availability['available'];
6064
}
61-
return $availability['available'];
65+
return $this->available;
6266
}
6367

6468
/**
@@ -257,6 +261,7 @@ protected function setUnavailable(?StorageNotAvailableException $e): void {
257261
self::RECHECK_TTL_SEC
258262
);
259263
}
264+
$this->available = false;
260265
$this->getStorageCache()->setAvailability(false, $delay);
261266
if ($e !== null) {
262267
throw $e;

tests/lib/Files/Storage/Wrapper/AvailabilityTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,30 @@ public function testAvailableThrow(): void {
150150

151151
$this->wrapper->mkdir('foobar');
152152
}
153+
154+
public function testUnavailableMultiple(): void {
155+
$this->storage->expects($this->once())
156+
->method('getAvailability')
157+
->willReturn(['available' => true, 'last_checked' => 0]);
158+
$this->storage->expects($this->never())
159+
->method('test');
160+
$this->storage
161+
->expects($this->once()) // load-bearing `once`
162+
->method('mkdir')
163+
->willThrowException(new StorageNotAvailableException());
164+
165+
try {
166+
$this->wrapper->mkdir('foobar');
167+
$this->fail();
168+
} catch (StorageNotAvailableException) {
169+
}
170+
171+
$this->storage->expects($this->never())->method('file_exists');
172+
173+
try {
174+
$this->wrapper->mkdir('foobar');
175+
$this->fail();
176+
} catch (StorageNotAvailableException) {
177+
}
178+
}
153179
}

0 commit comments

Comments
 (0)