Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static function getNumericStorageId($storageId) {
}

/**
* @return array [ available, last_checked ]
* @return array{available: bool, last_checked: int}
*/
public function getAvailability() {
if ($row = self::getStorageById($this->storageId)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Storage/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ private function getLockLogger(): ?LoggerInterface {
}

/**
* @return array [ available, last_checked ]
* @return array{available: bool, last_checked: int}
*/
public function getAvailability(): array {
return $this->getStorageCache()->getAvailability();
Expand Down
13 changes: 9 additions & 4 deletions lib/private/Files/Storage/Wrapper/Availability.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Availability extends Wrapper {

/** @var IConfig */
protected $config;
protected ?bool $available = null;

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

private function isAvailable(): bool {
$availability = $this->getAvailability();
if (self::shouldRecheck($availability)) {
return $this->updateAvailability();
if (is_null($this->available)) {
$availability = $this->getAvailability();
if (self::shouldRecheck($availability)) {
return $this->updateAvailability();
}
$this->available = $availability['available'];
}
return $availability['available'];
return $this->available;
}

/**
Expand Down Expand Up @@ -257,6 +261,7 @@ protected function setUnavailable(?StorageNotAvailableException $e): void {
self::RECHECK_TTL_SEC
);
}
$this->available = false;
$this->getStorageCache()->setAvailability(false, $delay);
if ($e !== null) {
throw $e;
Expand Down
26 changes: 26 additions & 0 deletions tests/lib/Files/Storage/Wrapper/AvailabilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,30 @@ public function testAvailableThrow(): void {

$this->wrapper->mkdir('foobar');
}

public function testUnavailableMultiple(): void {
$this->storage->expects($this->once())
->method('getAvailability')
->willReturn(['available' => true, 'last_checked' => 0]);
$this->storage->expects($this->never())
->method('test');
$this->storage
->expects($this->once()) // load-bearing `once`
->method('mkdir')
->willThrowException(new StorageNotAvailableException());

try {
$this->wrapper->mkdir('foobar');
$this->fail();
} catch (StorageNotAvailableException) {
}

$this->storage->expects($this->never())->method('file_exists');

try {
$this->wrapper->mkdir('foobar');
$this->fail();
} catch (StorageNotAvailableException) {
}
}
}
Loading