From 475c84722fe5a77d1b009b2437414fdc2db1189f Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Wed, 8 Oct 2025 17:13:09 +0200 Subject: [PATCH] refactor(IPropagator): Cleanup implementation - Add missing type hinting - Use only public methods from IStorage instead of relying on internal \OC\Storage methods - Refactor HomePropagator to use ignore argument from Propagator instead of reimplementing the same logic. Signed-off-by: Carl Schwan --- lib/private/Files/Cache/HomePropagator.php | 28 ++----- lib/private/Files/Cache/Propagator.php | 74 +++++++------------ .../Files/Cache/Wrapper/JailPropagator.php | 21 ++---- lib/private/Files/Storage/Wrapper/Jail.php | 4 +- lib/public/Files/Cache/IPropagator.php | 20 +++-- 5 files changed, 54 insertions(+), 93 deletions(-) diff --git a/lib/private/Files/Cache/HomePropagator.php b/lib/private/Files/Cache/HomePropagator.php index d4ac8a7c8e3..f42e1d880ad 100644 --- a/lib/private/Files/Cache/HomePropagator.php +++ b/lib/private/Files/Cache/HomePropagator.php @@ -1,5 +1,7 @@ ignoredBaseFolders = ['files_encryption']; - } - - - /** - * @param string $internalPath - * @param int $time - * @param int $sizeDifference number of bytes the file has grown - */ - public function propagateChange($internalPath, $time, $sizeDifference = 0) { - [$baseFolder] = explode('/', $internalPath, 2); - if (in_array($baseFolder, $this->ignoredBaseFolders)) { - return []; - } else { - parent::propagateChange($internalPath, $time, $sizeDifference); - } + public function __construct(IStorage $storage, IDBConnection $connection) { + parent::__construct($storage, $connection, ignore: ['files_encryption']); } } diff --git a/lib/private/Files/Cache/Propagator.php b/lib/private/Files/Cache/Propagator.php index a6ba87896f4..557d055c67b 100644 --- a/lib/private/Files/Cache/Propagator.php +++ b/lib/private/Files/Cache/Propagator.php @@ -1,5 +1,7 @@ storage = $storage; - $this->connection = $connection; - $this->ignore = $ignore; + public function __construct( + protected readonly IStorage $storage, + private readonly IDBConnection $connection, + private readonly array $ignore = [], + ) { $this->clock = Server::get(ClockInterface::class); } - /** - * @param string $internalPath - * @param int $time - * @param int $sizeDifference number of bytes the file has grown - */ - public function propagateChange($internalPath, $time, $sizeDifference = 0) { + #[Override] + public function propagateChange(string $internalPath, int $time, int $sizeDifference = 0): void { // Do not propagate changes in ignored paths foreach ($this->ignore as $ignore) { if (str_starts_with($internalPath, $ignore)) { @@ -63,9 +45,9 @@ class Propagator implements IPropagator { } } - $time = min((int)$time, $this->clock->now()->getTimestamp()); + $time = min($time, $this->clock->now()->getTimestamp()); - $storageId = $this->storage->getStorageCache()->getNumericId(); + $storageId = $this->storage->getCache()->getNumericStorageId(); $parents = $this->getParents($internalPath); @@ -137,7 +119,10 @@ class Propagator implements IPropagator { } } - protected function getParents($path) { + /** + * @return string[] + */ + protected function getParents(string $path): array { $parts = explode('/', $path); $parent = ''; $parents = []; @@ -148,19 +133,12 @@ class Propagator implements IPropagator { return $parents; } - /** - * Mark the beginning of a propagation batch - * - * Note that not all cache setups support propagation in which case this will be a noop - * - * Batching for cache setups that do support it has to be explicit since the cache state is not fully consistent - * before the batch is committed. - */ - public function beginBatch() { + #[Override] + public function beginBatch(): void { $this->inBatch = true; } - private function addToBatch($internalPath, $time, $sizeDifference) { + private function addToBatch(string $internalPath, int $time, int $sizeDifference): void { if (!isset($this->batch[$internalPath])) { $this->batch[$internalPath] = [ 'hash' => md5($internalPath), @@ -175,10 +153,8 @@ class Propagator implements IPropagator { } } - /** - * Commit the active propagation batch - */ - public function commitBatch() { + #[Override] + public function commitBatch(): void { if (!$this->inBatch) { throw new \BadMethodCallException('Not in batch'); } @@ -187,7 +163,7 @@ class Propagator implements IPropagator { $this->connection->beginTransaction(); $query = $this->connection->getQueryBuilder(); - $storageId = (int)$this->storage->getStorageCache()->getNumericId(); + $storageId = $this->storage->getCache()->getNumericStorageId(); $query->update('filecache') ->set('mtime', $query->func()->greatest('mtime', $query->createParameter('time'))) diff --git a/lib/private/Files/Cache/Wrapper/JailPropagator.php b/lib/private/Files/Cache/Wrapper/JailPropagator.php index d6409b7875e..2b5b5a2d6a1 100644 --- a/lib/private/Files/Cache/Wrapper/JailPropagator.php +++ b/lib/private/Files/Cache/Wrapper/JailPropagator.php @@ -1,5 +1,7 @@ storage->resolvePath($internalPath); + #[Override] + public function propagateChange(string $internalPath, int $time, int $sizeDifference = 0): void { + /** @var Jail $jail */ + $jail = $this->storage; + [$storage, $sourceInternalPath] = $jail->resolvePath($internalPath); $storage->getPropagator()->propagateChange($sourceInternalPath, $time, $sizeDifference); } } diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php index 38b113cef88..3ce6e6bb3b6 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -215,7 +215,9 @@ class Jail extends Wrapper { } /** - * Resolve the path for the source of the share + * Resolve the path for the source of the share. + * + * @return array{0: IStorage, 1: string} */ public function resolvePath(string $path): array { return [$this->getWrapperStorage(), $this->getUnjailedPath($path)]; diff --git a/lib/public/Files/Cache/IPropagator.php b/lib/public/Files/Cache/IPropagator.php index 703cba59599..620da29057c 100644 --- a/lib/public/Files/Cache/IPropagator.php +++ b/lib/public/Files/Cache/IPropagator.php @@ -1,20 +1,26 @@