Skip to content

Commit c3abeeb

Browse files
cuppettclaude
andcommitted
fix(encryption): Resolve IAppConfig lazily to prevent early IDBConnection creation
Injecting IAppConfig as a constructor parameter into Encryption\Manager (and through it into EncryptionWrapper) caused IDBConnection to be eagerly resolved during OC::init() on PHP <8.4 (no lazy ghost objects). This happened before maintenance:install's Sqlite::initialize() wrote dbname to config.php, so the connection latched onto the default database name ('owncloud') instead of the configured one ('nextcloud'). All migrations then ran against owncloud.db, and the subsequent enable_all.php process opened an empty nextcloud.db — crashing with "no such table: oc_appconfig". Remove IAppConfig from Manager's constructor and Server.php's factory closure. Resolve it lazily via Server::get(IAppConfig::class) inside EncryptionWrapper::wrapStorage(), which is only called after the filesystem is set up, never during bootstrap. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Stephen Cuppett <steve@cuppett.com>
1 parent fd1c3e0 commit c3abeeb

4 files changed

Lines changed: 6 additions & 15 deletions

File tree

lib/private/Encryption/EncryptionWrapper.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class EncryptionWrapper {
3939
public function __construct(
4040
private ArrayCache $arrayCache,
4141
private Manager $manager,
42-
private IAppConfig $appConfig,
4342
private LoggerInterface $logger,
4443
) {
4544
}
@@ -73,8 +72,8 @@ public function wrapStorage(string $mountPoint, IStorage $storage, IMountPoint $
7372
}
7473

7574
// Skip encryption for home mounts if encryptHomeStorage is disabled
76-
if ($mount instanceof HomeMountPoint &&
77-
!$this->appConfig->getValueBool('encryption', 'encryptHomeStorage', true)) {
75+
if ($mount instanceof HomeMountPoint
76+
&& !Server::get(IAppConfig::class)->getValueBool('encryption', 'encryptHomeStorage', true)) {
7877
return $storage;
7978
}
8079
}

lib/private/Encryption/Manager.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use OCP\Encryption\IManager;
1919
use OCP\Files\Mount\IMountPoint;
2020
use OCP\Files\Storage\IStorage;
21-
use OCP\IAppConfig;
2221
use OCP\IConfig;
2322
use OCP\IL10N;
2423
use Psr\Log\LoggerInterface;
@@ -33,7 +32,6 @@ public function __construct(
3332
protected View $rootView,
3433
protected Util $util,
3534
protected ArrayCache $arrayCache,
36-
protected IAppConfig $appConfig,
3735
) {
3836
$this->encryptionModules = [];
3937
}
@@ -207,13 +205,13 @@ public function getDefaultEncryptionModuleId() {
207205
public function setupStorage() {
208206
// If encryption is disabled and there are no loaded modules it makes no sense to load the wrapper
209207
if (!empty($this->encryptionModules) || $this->isEnabled()) {
210-
$encryptionWrapper = new EncryptionWrapper($this->arrayCache, $this, $this->appConfig, $this->logger);
208+
$encryptionWrapper = new EncryptionWrapper($this->arrayCache, $this, $this->logger);
211209
Filesystem::addStorageWrapper('oc_encryption', [$encryptionWrapper, 'wrapStorage'], 2);
212210
}
213211
}
214212

215213
public function forceWrapStorage(IMountPoint $mountPoint, IStorage $storage) {
216-
$encryptionWrapper = new EncryptionWrapper($this->arrayCache, $this, $this->appConfig, $this->logger);
214+
$encryptionWrapper = new EncryptionWrapper($this->arrayCache, $this, $this->logger);
217215
return $encryptionWrapper->wrapStorage($mountPoint->getMountPoint(), $storage, $mountPoint, true);
218216
}
219217

lib/private/Server.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,7 @@ public function __construct(
384384
$c->getL10N('core'),
385385
new View(),
386386
$util,
387-
new ArrayCache(),
388-
$c->get(IAppConfig::class),
387+
new ArrayCache()
389388
);
390389
});
391390
$this->registerAlias(\OCP\Encryption\IManager::class, Encryption\Manager::class);

tests/lib/Encryption/EncryptionWrapperTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use OCA\Files_Trashbin\Storage;
1616
use OCP\Files\Mount\IMountPoint;
1717
use OCP\Files\Storage\IDisableEncryptionStorage;
18-
use OCP\IAppConfig;
1918
use Psr\Log\LoggerInterface;
2019
use Test\TestCase;
2120

@@ -32,19 +31,15 @@ class EncryptionWrapperTest extends TestCase {
3231
/** @var \PHPUnit\Framework\MockObject\MockObject|ArrayCache */
3332
private $arrayCache;
3433

35-
/** @var \PHPUnit\Framework\MockObject\MockObject|IAppConfig */
36-
private $appConfig;
37-
3834
#[\Override]
3935
protected function setUp(): void {
4036
parent::setUp();
4137

4238
$this->arrayCache = $this->createMock(ArrayCache::class);
4339
$this->manager = $this->createMock(Manager::class);
4440
$this->logger = $this->createMock(LoggerInterface::class);
45-
$this->appConfig = $this->createMock(IAppConfig::class);
4641

47-
$this->instance = new EncryptionWrapper($this->arrayCache, $this->manager, $this->appConfig, $this->logger);
42+
$this->instance = new EncryptionWrapper($this->arrayCache, $this->manager, $this->logger);
4843
}
4944

5045

0 commit comments

Comments
 (0)