Skip to content
Open
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
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1649,6 +1649,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\\PrimaryObjectStoreConfig' => $baseDir . '/lib/private/Files/ObjectStore/PrimaryObjectStoreConfig.php',
'OC\\Files\\ObjectStore\\S3' => $baseDir . '/lib/private/Files/ObjectStore/S3.php',
'OC\\Files\\ObjectStore\\S3ConfigTrait' => $baseDir . '/lib/private/Files/ObjectStore/S3ConfigTrait.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,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\\PrimaryObjectStoreConfig' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/PrimaryObjectStoreConfig.php',
'OC\\Files\\ObjectStore\\S3' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/S3.php',
'OC\\Files\\ObjectStore\\S3ConfigTrait' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/S3ConfigTrait.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 @@ -272,7 +272,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
49 changes: 45 additions & 4 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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 @@ -152,7 +153,23 @@
return false;
}

return $this->rmObjects($entry);
$result = $this->rmObjects($entry);
if ($result) {
$this->removeFromCache($entry);
}
return $result;
}

/**
* Remove an item from cache and propagate the change to the parent folders.
*
* Similar logic to the `Updater` but done in-storage because we have the correct info to avoid expensive
* folder size calculations.
*/
private function removeFromCache(ICacheEntry $entry): void {
$this->cache->remove($entry->getId());

Check failure on line 170 in lib/private/Files/ObjectStore/ObjectStoreStorage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidArgument

lib/private/Files/ObjectStore/ObjectStoreStorage.php:170:24: InvalidArgument: Argument 1 of OC\Files\Cache\Cache::remove expects string, but int provided (see https://psalm.dev/004)
$this->getUpdater()->correctParentStorageMtime($entry->getPath());
$this->propagator->propagateChange($entry->getPath(), time(), -$entry->getSize());
}

private function rmObjects(ICacheEntry $entry): bool {
Expand All @@ -179,15 +196,21 @@
public function unlink(string $path): bool {
$path = $this->normalizePath($path);
$entry = $this->getCache()->get($path);
$result = false;

if ($entry instanceof ICacheEntry) {
if ($entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
return $this->rmObjects($entry);
$result = $this->rmObjects($entry);
} else {
return $this->rmObject($entry);
$result = $this->rmObject($entry);
}
}
return false;

if ($result) {
$this->removeFromCache($entry);
}

return $result;
}

public function rmObject(ICacheEntry $entry): bool {
Expand Down Expand Up @@ -464,6 +487,7 @@
}
// 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 @@ -561,6 +585,9 @@
}
}

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

return $size;
}

Expand Down Expand Up @@ -814,4 +841,18 @@
public function setPreserveCacheOnDelete(bool $preserve) {
$this->preserveCacheItemsOnDelete = $preserve;
}

public function getUpdater(?IStorage $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;
}
}
25 changes: 25 additions & 0 deletions lib/private/Files/ObjectStore/ObjectStoreUpdater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Files\ObjectStore;

use OC\Files\Cache\Updater;

/**
* Custom Updater class for `ObjectStoreStorage`.
* This wrapper will do nothing when the `update` method is called.
* This is to skip heavy cache operations, as they are already done in `ObjectStoreStorage`.
*/
class ObjectStoreUpdater extends Updater {
public function update($path, $time = null, ?int $sizeDifference = null) {
// Noop
}

public function remove($path) {
// Noop
}
}
4 changes: 4 additions & 0 deletions lib/public/Files/Cache/IUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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 @@ -37,6 +38,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 @@ -45,6 +47,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 @@ -55,6 +58,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