aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis Chemineau <louis@chmn.me>2025-06-10 17:41:57 +0200
committerRobin Appelman <robin@icewind.nl>2025-06-13 17:27:04 +0200
commit37d5cfebcfe3bc732b8709844d21899c510be52b (patch)
tree361c1a91879dfc687447e3a481e081286f7b86c2
parentdab944fd6a9c1cdc354d056275a438a2e9896455 (diff)
downloadnextcloud-server-artonge/feat/implement_custom_updater_for_object_storage-squashed-29.tar.gz
nextcloud-server-artonge/feat/implement_custom_updater_for_object_storage-squashed-29.zip
feat: Implement custom Updater for object store storageartonge/feat/implement_custom_updater_for_object_storage-squashed-29
fix: fix incorrect filesize for object store touch test: improve version storage test Signed-off-by: Robin Appelman <robin@icewind.nl> Signed-off-by: Louis Chemineau <louis@chmn.me>
-rw-r--r--apps/files_versions/tests/StorageTest.php4
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php9
-rw-r--r--lib/private/Files/Cache/Updater.php2
-rw-r--r--lib/private/Files/ObjectStore/ObjectStoreStorage.php21
-rw-r--r--lib/private/Files/ObjectStore/ObjectStoreUpdater.php41
-rw-r--r--lib/public/Files/Cache/IUpdater.php4
7 files changed, 74 insertions, 8 deletions
diff --git a/apps/files_versions/tests/StorageTest.php b/apps/files_versions/tests/StorageTest.php
index ba9bcf0705a..c9838a92604 100644
--- a/apps/files_versions/tests/StorageTest.php
+++ b/apps/files_versions/tests/StorageTest.php
@@ -63,10 +63,10 @@ class StorageTest extends TestCase {
protected function createPastFile(string $path, int $mtime) {
try {
$file = $this->userFolder->get($path);
+ $file->putContent((string)$mtime);
} catch (NotFoundException $e) {
- $file = $this->userFolder->newFile($path);
+ $file = $this->userFolder->newFile($path, (string)$mtime);
}
- $file->putContent((string)$mtime);
$file->touch($mtime);
}
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 8aad40d2420..269a038e7e8 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -1439,6 +1439,7 @@ return array(
'OC\\Files\\ObjectStore\\Mapper' => $baseDir . '/lib/private/Files/ObjectStore/Mapper.php',
'OC\\Files\\ObjectStore\\ObjectStoreScanner' => $baseDir . '/lib/private/Files/ObjectStore/ObjectStoreScanner.php',
'OC\\Files\\ObjectStore\\ObjectStoreStorage' => $baseDir . '/lib/private/Files/ObjectStore/ObjectStoreStorage.php',
+ 'OC\\Files\\ObjectStore\\ObjectStoreUpdater' => $baseDir . '/lib/private/Files/ObjectStore/ObjectStoreUpdater.php',
'OC\\Files\\ObjectStore\\S3' => $baseDir . '/lib/private/Files/ObjectStore/S3.php',
'OC\\Files\\ObjectStore\\S3ConfigTrait' => $baseDir . '/lib/private/Files/ObjectStore/S3ConfigTrait.php',
'OC\\Files\\ObjectStore\\S3ConnectionTrait' => $baseDir . '/lib/private/Files/ObjectStore/S3ConnectionTrait.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 227b9c4b106..8639206ef2e 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -11,7 +11,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
);
public static $prefixLengthsPsr4 = array (
- 'O' =>
+ 'O' =>
array (
'OC\\Core\\' => 8,
'OC\\' => 3,
@@ -20,15 +20,15 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
);
public static $prefixDirsPsr4 = array (
- 'OC\\Core\\' =>
+ 'OC\\Core\\' =>
array (
0 => __DIR__ . '/../../..' . '/core',
),
- 'OC\\' =>
+ 'OC\\' =>
array (
0 => __DIR__ . '/../../..' . '/lib/private',
),
- 'OCP\\' =>
+ 'OCP\\' =>
array (
0 => __DIR__ . '/../../..' . '/lib/public',
),
@@ -1472,6 +1472,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Files\\ObjectStore\\Mapper' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/Mapper.php',
'OC\\Files\\ObjectStore\\ObjectStoreScanner' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/ObjectStoreScanner.php',
'OC\\Files\\ObjectStore\\ObjectStoreStorage' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/ObjectStoreStorage.php',
+ 'OC\\Files\\ObjectStore\\ObjectStoreUpdater' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/ObjectStoreUpdater.php',
'OC\\Files\\ObjectStore\\S3' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/S3.php',
'OC\\Files\\ObjectStore\\S3ConfigTrait' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/S3ConfigTrait.php',
'OC\\Files\\ObjectStore\\S3ConnectionTrait' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/S3ConnectionTrait.php',
diff --git a/lib/private/Files/Cache/Updater.php b/lib/private/Files/Cache/Updater.php
index a07741e1fd4..30bbb257d83 100644
--- a/lib/private/Files/Cache/Updater.php
+++ b/lib/private/Files/Cache/Updater.php
@@ -281,7 +281,7 @@ class Updater implements IUpdater {
*
* @param string $internalPath
*/
- private function correctParentStorageMtime($internalPath) {
+ public function correctParentStorageMtime($internalPath) {
$parentId = $this->cache->getParentId($internalPath);
$parent = dirname($internalPath);
if ($parentId != -1) {
diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
index 5a2aaa4dc50..e7773d680d2 100644
--- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php
+++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
@@ -37,6 +37,7 @@ use Icewind\Streams\CountWrapper;
use Icewind\Streams\IteratorDirectory;
use OC\Files\Cache\Cache;
use OC\Files\Cache\CacheEntry;
+use OC\Files\Cache\Updater;
use OC\Files\Storage\PolyFill\CopyDirectory;
use OCP\Files\Cache\ICache;
use OCP\Files\Cache\ICacheEntry;
@@ -449,7 +450,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
$stat = [
'etag' => $this->getETag($path),
'mimetype' => $mimeType,
- 'size' => 0,
+ 'size' => 1,
'mtime' => $mtime,
'storage_mtime' => $mtime,
'permissions' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE,
@@ -506,6 +507,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
}
// update stat with new data
$mTime = time();
+ $oldSize = $stat['size'] ?? 0;
$stat['size'] = (int)$size;
$stat['mtime'] = $mTime;
$stat['storage_mtime'] = $mTime;
@@ -590,6 +592,9 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
}
}
+ $this->getUpdater()->correctParentStorageMtime($path);
+ $this->propagator->propagateChange($path, $mTime, $stat['size'] - $oldSize);
+
return $size;
}
@@ -836,4 +841,18 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
public function setPreserveCacheOnDelete(bool $preserve) {
$this->preserveCacheItemsOnDelete = $preserve;
}
+
+ public function getUpdater($storage = null): Updater {
+ if (!$storage) {
+ $storage = $this;
+ }
+ if (!$storage->instanceOfStorage(self::class)) {
+ throw new \InvalidArgumentException('Storage is not of the correct class');
+ }
+ /** @var self $storage */
+ if (!isset($storage->updater)) {
+ $storage->updater = new ObjectStoreUpdater($storage);
+ }
+ return $storage->updater;
+ }
}
diff --git a/lib/private/Files/ObjectStore/ObjectStoreUpdater.php b/lib/private/Files/ObjectStore/ObjectStoreUpdater.php
new file mode 100644
index 00000000000..04bc1b018bc
--- /dev/null
+++ b/lib/private/Files/ObjectStore/ObjectStoreUpdater.php
@@ -0,0 +1,41 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+namespace OC\Files\ObjectStore;
+
+use OC\Files\Cache\Updater;
+use OCP\Files\Storage\IStorage;
+
+/**
+ * Custom wrapper around the Updater for ObjectStoreStorage.
+ * This wrapper will skip updating the cache in some scenario.
+ * This is because a lot of cache management is already done in ObjectStoreStorage.
+ */
+class ObjectStoreUpdater extends Updater {
+ public function getPropagator() {
+ return parent::getPropagator();
+ }
+
+ public function propagate($path, $time = null) {
+ parent::propagate($path, $time);
+ }
+
+ public function update($path, $time = null, ?int $sizeDifference = null) {
+ // Noop
+ }
+
+ public function remove($path) {
+ parent::remove($path);
+ }
+
+ public function renameFromStorage(IStorage $sourceStorage, $source, $target) {
+ parent::renameFromStorage($sourceStorage, $source, $target);
+ }
+
+ public function copyFromStorage(IStorage $sourceStorage, string $source, string $target): void {
+ parent::copyFromStorage($sourceStorage, $source, $target);
+ }
+}
diff --git a/lib/public/Files/Cache/IUpdater.php b/lib/public/Files/Cache/IUpdater.php
index 7a42587b809..175e46365b4 100644
--- a/lib/public/Files/Cache/IUpdater.php
+++ b/lib/public/Files/Cache/IUpdater.php
@@ -42,6 +42,7 @@ interface IUpdater {
*
* @param string $path the path of the file to propagate the changes for
* @param int|null $time the timestamp to set as mtime for the parent folders, if left out the current time is used
+ * @return void
* @since 9.0.0
*/
public function propagate($path, $time = null);
@@ -51,6 +52,7 @@ interface IUpdater {
*
* @param string $path
* @param int $time
+ * @return void
* @since 9.0.0
*/
public function update($path, $time = null, ?int $sizeDifference = null);
@@ -59,6 +61,7 @@ interface IUpdater {
* Remove $path from the cache and update the size, etag and mtime of the parent folders
*
* @param string $path
+ * @return void
* @since 9.0.0
*/
public function remove($path);
@@ -69,6 +72,7 @@ interface IUpdater {
* @param IStorage $sourceStorage
* @param string $source
* @param string $target
+ * @return void
* @since 9.0.0
*/
public function renameFromStorage(IStorage $sourceStorage, $source, $target);