Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ext storage Local to go unavailable #39707

Merged
merged 1 commit into from
Sep 4, 2023
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
6 changes: 6 additions & 0 deletions apps/files_external/lib/Lib/Backend/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
use OCA\Files_External\Lib\Auth\AuthMechanism;
use OCA\Files_External\Lib\Auth\NullMechanism;
use OCA\Files_External\Lib\DefinitionParameter;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Service\BackendService;
use OCP\IL10N;
use OCP\IUser;

class Local extends Backend {
public function __construct(IL10N $l, NullMechanism $legacyAuth) {
Expand All @@ -45,4 +47,8 @@ public function __construct(IL10N $l, NullMechanism $legacyAuth) {
->setLegacyAuthMechanism($legacyAuth)
;
}

public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null): void {
$storage->setBackendOption('isExternal', true);
}
}
7 changes: 7 additions & 0 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
use OCP\Files\GenericFileException;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\Storage\IStorage;
use OCP\Files\StorageNotAvailableException;
use OCP\IConfig;
use OCP\Util;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -95,6 +96,12 @@ public function __construct($arguments) {

// support Write-Once-Read-Many file systems
$this->unlinkOnTruncate = $this->config->getSystemValueBool('localstorage.unlink_on_truncate', false);

if (isset($arguments['isExternal']) && $arguments['isExternal'] && !$this->stat('')) {
// data dir not accessible or available, can happen when using an external storage of type Local
// on an unmounted system mount point
throw new StorageNotAvailableException('Local storage path does not exist "' . $this->getSourcePath('') . '"');
}
}

public function __destruct() {
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/Files/Storage/LocalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,15 @@ public function testWriteUmaskCopy() {
umask($oldMask);
$this->assertTrue($this->instance->isUpdatable('test.txt'));
}

public function testUnavailableExternal() {
$this->expectException(\OCP\Files\StorageNotAvailableException::class);
$this->instance = new \OC\Files\Storage\Local(['datadir' => $this->tmpDir . '/unexist', 'isExternal' => true]);
}

public function testUnavailableNonExternal() {
$this->instance = new \OC\Files\Storage\Local(['datadir' => $this->tmpDir . '/unexist']);
// no exception thrown
$this->assertNotNull($this->instance);
}
}
Loading