diff --git a/lib/private/Files/Cache/HomePropagator.php b/lib/private/Files/Cache/HomePropagator.php index d4ac8a7c8e3db..f42e1d880ad44 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 a6ba87896f4de..557d055c67b9f 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 @@ public function propagateChange($internalPath, $time, $sizeDifference = 0) { } } - $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 @@ public function propagateChange($internalPath, $time, $sizeDifference = 0) { } } - protected function getParents($path) { + /** + * @return string[] + */ + protected function getParents(string $path): array { $parts = explode('/', $path); $parent = ''; $parents = []; @@ -148,19 +133,12 @@ protected function getParents($path) { 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 @@ private function addToBatch($internalPath, $time, $sizeDifference) { } } - /** - * 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 @@ public function commitBatch() { $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 d6409b7875e51..2b5b5a2d6a1e3 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 38b113cef889e..3ce6e6bb3b6d3 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -215,7 +215,9 @@ public function changeLock(string $path, int $type, ILockingProvider $provider): } /** - * 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 703cba59599f8..620da29057c7a 100644 --- a/lib/public/Files/Cache/IPropagator.php +++ b/lib/public/Files/Cache/IPropagator.php @@ -1,20 +1,26 @@