Backend: an existing folder that cannot be listed is an error, not empty
Read as empty, a catalog/ or index/ folder would make an existing repository look new.
This commit is contained in:
@@ -114,7 +114,10 @@ final class LocalBackend implements IBackend {
|
|||||||
}
|
}
|
||||||
$result = [];
|
$result = [];
|
||||||
$names = scandir($base);
|
$names = scandir($base);
|
||||||
foreach ($names === false ? [] : $names as $name) {
|
if ($names === false) {
|
||||||
|
throw new BackendException('Cannot list ' . $dir);
|
||||||
|
}
|
||||||
|
foreach ($names as $name) {
|
||||||
if ($name !== '.' && $name !== '..' && !StorageBackend::isTemporary($name)) {
|
if ($name !== '.' && $name !== '..' && !StorageBackend::isTemporary($name)) {
|
||||||
$result[] = trim($dir, '/') . '/' . $name;
|
$result[] = trim($dir, '/') . '/' . $name;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,8 @@ final class StorageBackend implements IBackend {
|
|||||||
}
|
}
|
||||||
$dh = $this->storage->opendir($abs);
|
$dh = $this->storage->opendir($abs);
|
||||||
if ($dh === false) {
|
if ($dh === false) {
|
||||||
return [];
|
// An existing folder read as empty would look like a new repository.
|
||||||
|
throw new BackendException('Cannot list ' . $dir);
|
||||||
}
|
}
|
||||||
$cut = $this->base === '' ? 0 : strlen($this->base) + 1;
|
$cut = $this->base === '' ? 0 : strlen($this->base) + 1;
|
||||||
$result = [];
|
$result = [];
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace OCA\NgBackup\Tests\Unit\Backend;
|
namespace OCA\NgBackup\Tests\Unit\Backend;
|
||||||
|
|
||||||
|
use OCA\NgBackup\Backend\BackendException;
|
||||||
use OCA\NgBackup\Backend\StorageBackend;
|
use OCA\NgBackup\Backend\StorageBackend;
|
||||||
use OCA\NgBackup\Tests\Unit\TempDirTrait;
|
use OCA\NgBackup\Tests\Unit\TempDirTrait;
|
||||||
use OCP\Files\Storage\IStorage;
|
use OCP\Files\Storage\IStorage;
|
||||||
@@ -44,4 +45,13 @@ class StorageBackendListTest extends TestCase {
|
|||||||
$storage->expects($this->never())->method('opendir');
|
$storage->expects($this->never())->method('opendir');
|
||||||
$this->assertSame([], (new StorageBackend($storage, 'repo'))->listFiles('snapshots'));
|
$this->assertSame([], (new StorageBackend($storage, 'repo'))->listFiles('snapshots'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAnUnreadableFolderIsAnErrorNotEmpty(): void {
|
||||||
|
$storage = $this->createMock(IStorage::class);
|
||||||
|
$storage->method('instanceOfStorage')->willReturn(false);
|
||||||
|
$storage->method('is_dir')->willReturn(true);
|
||||||
|
$storage->method('opendir')->willReturn(false);
|
||||||
|
$this->expectException(BackendException::class);
|
||||||
|
(new StorageBackend($storage, 'repo'))->listFiles('catalog');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user