Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/files_versions/tests/StorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ protected function setUp(): void {
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);
}

Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,7 @@
'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',
Expand Down
9 changes: 5 additions & 4 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
);

public static $prefixLengthsPsr4 = array (
'O' =>
'O' =>
array (
'OC\\Core\\' => 8,
'OC\\' => 3,
Expand All @@ -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',
),
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private function updateStorageMTimeOnly($internalPath) {
*
* @param string $internalPath
*/
private function correctParentStorageMtime($internalPath) {
public function correctParentStorageMtime($internalPath) {
$parentId = $this->cache->getParentId($internalPath);
$parent = dirname($internalPath);
if ($parentId != -1) {
Expand Down
21 changes: 20 additions & 1 deletion lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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;
Expand Down Expand Up @@ -449,7 +450,7 @@ public function touch($path, $mtime = null) {
$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,
Expand Down Expand Up @@ -506,6 +507,7 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
}
// update stat with new data
$mTime = time();
$oldSize = $stat['size'] ?? 0;
$stat['size'] = (int)$size;
$stat['mtime'] = $mTime;
$stat['storage_mtime'] = $mTime;
Expand Down Expand Up @@ -590,6 +592,9 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
}
}

$this->getUpdater()->correctParentStorageMtime($path);
$this->propagator->propagateChange($path, $mTime, $stat['size'] - $oldSize);

return $size;
}

Expand Down Expand Up @@ -836,4 +841,18 @@ public function cancelChunkedWrite(string $targetPath, string $writeToken): void
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;
}
}
41 changes: 41 additions & 0 deletions lib/private/Files/ObjectStore/ObjectStoreUpdater.php
Original file line number Diff line number Diff line change
@@ -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);
}
}
4 changes: 4 additions & 0 deletions lib/public/Files/Cache/IUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function getPropagator();
*
* @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);
Expand All @@ -51,6 +52,7 @@ public function propagate($path, $time = null);
*
* @param string $path
* @param int $time
* @return void
* @since 9.0.0
*/
public function update($path, $time = null, ?int $sizeDifference = null);
Expand All @@ -59,6 +61,7 @@ public function update($path, $time = null, ?int $sizeDifference = null);
* 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);
Expand All @@ -69,6 +72,7 @@ public function remove($path);
* @param IStorage $sourceStorage
* @param string $source
* @param string $target
* @return void
* @since 9.0.0
*/
public function renameFromStorage(IStorage $sourceStorage, $source, $target);
Expand Down
Loading