Skip to content

Commit

Permalink
Merge pull request #39707 from nextcloud/bugfix/39706/local-ext-stora…
Browse files Browse the repository at this point in the history
…ge-unavailable-mode
  • Loading branch information
szaimen authored Sep 4, 2023
2 parents 373f3f6 + 8d1a3da commit 489a57e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
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);
}
}

0 comments on commit 489a57e

Please sign in to comment.