diff options
author | Louis <louis@chmn.me> | 2024-12-04 16:58:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-04 16:58:01 +0100 |
commit | 27331d48e377d5e908439cfdef8950b4b5ec47b2 (patch) | |
tree | 87d5b9c050bdf411fdc23cb44e566c1ddf914c59 /lib/private/Files | |
parent | c77243d568d2039b04c2e633be496d981235f665 (diff) | |
parent | 425e0c3660fb61d9eab816cd76f1d26a7c8118e4 (diff) | |
download | nextcloud-server-27331d48e377d5e908439cfdef8950b4b5ec47b2.tar.gz nextcloud-server-27331d48e377d5e908439cfdef8950b4b5ec47b2.zip |
Merge pull request #48651 from nextcloud/artonge/fix/copy_cache_during_copy_operations
fix(files): Correctly copy the cache information during copy operations
Diffstat (limited to 'lib/private/Files')
-rw-r--r-- | lib/private/Files/Cache/Updater.php | 41 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Encryption.php | 1 | ||||
-rw-r--r-- | lib/private/Files/View.php | 10 |
3 files changed, 41 insertions, 11 deletions
diff --git a/lib/private/Files/Cache/Updater.php b/lib/private/Files/Cache/Updater.php index eab68b4f545..aa025a3a96c 100644 --- a/lib/private/Files/Cache/Updater.php +++ b/lib/private/Files/Cache/Updater.php @@ -9,6 +9,8 @@ namespace OC\Files\Cache; use Doctrine\DBAL\Exception\DeadlockException; use OC\Files\FileInfo; +use OC\Files\ObjectStore\ObjectStoreStorage; +use OCP\Files\Cache\ICache; use OCP\Files\Cache\ICacheEntry; use OCP\Files\Cache\IUpdater; use OCP\Files\Storage\IStorage; @@ -157,13 +159,40 @@ class Updater implements IUpdater { } /** - * Rename a file or folder in the cache and update the size, etag and mtime of the parent folders + * Rename a file or folder in the cache. * * @param IStorage $sourceStorage * @param string $source * @param string $target */ public function renameFromStorage(IStorage $sourceStorage, $source, $target) { + $this->copyOrRenameFromStorage($sourceStorage, $source, $target, function (ICache $sourceCache) use ($sourceStorage, $source, $target) { + // Remove existing cache entry to no reuse the fileId. + if ($this->cache->inCache($target)) { + $this->cache->remove($target); + } + + if ($sourceStorage === $this->storage) { + $this->cache->move($source, $target); + } else { + $this->cache->moveFromCache($sourceCache, $source, $target); + } + }); + } + + /** + * Copy a file or folder in the cache. + */ + public function copyFromStorage(IStorage $sourceStorage, string $source, string $target): void { + $this->copyOrRenameFromStorage($sourceStorage, $source, $target, function (ICache $sourceCache, ICacheEntry $sourceInfo) use ($target) { + $this->cache->copyFromCache($sourceCache, $sourceInfo, $target); + }); + } + + /** + * Utility to copy or rename a file or folder in the cache and update the size, etag and mtime of the parent folders + */ + private function copyOrRenameFromStorage(IStorage $sourceStorage, string $source, string $target, callable $operation): void { if (!$this->enabled or Scanner::isPartialFile($source) or Scanner::isPartialFile($target)) { return; } @@ -177,14 +206,8 @@ class Updater implements IUpdater { $sourceInfo = $sourceCache->get($source); if ($sourceInfo !== false) { - if ($this->cache->inCache($target)) { - $this->cache->remove($target); - } - - if ($sourceStorage === $this->storage) { - $this->cache->move($source, $target); - } else { - $this->cache->moveFromCache($sourceCache, $source, $target); + if (!$this->storage->instanceOfStorage(ObjectStoreStorage::class)) { + $operation($sourceCache, $sourceInfo); } $sourceExtension = pathinfo($source, PATHINFO_EXTENSION); diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index ba23f3c43ec..eb073d24087 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -628,7 +628,6 @@ class Encryption extends Wrapper { $info->getUnencryptedSize() ); } - $this->updateEncryptedVersion($sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename, true); } return $result; } diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 80679a9481f..66894e0c3cf 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -273,6 +273,12 @@ class View { } } + protected function copyUpdate(Storage $sourceStorage, Storage $targetStorage, string $sourceInternalPath, string $targetInternalPath): void { + if ($this->updaterEnabled) { + $targetStorage->getUpdater()->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); + } + } + /** * @param string $path * @return bool|mixed @@ -898,7 +904,9 @@ class View { $result = $storage2->copyFromStorage($storage1, $internalPath1, $internalPath2); } - $this->writeUpdate($storage2, $internalPath2); + if ($result) { + $this->copyUpdate($storage1, $storage2, $internalPath1, $internalPath2); + } $this->changeLock($target, ILockingProvider::LOCK_SHARED); $lockTypePath2 = ILockingProvider::LOCK_SHARED; |