From 09e89c776c08ec3b018b96fdf62cdaa46ad39502 Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 26 Apr 2026 09:48:39 -0400 Subject: [PATCH 1/2] fix(Files/Cache): harden MoveFromCacheTrait::moveFromCache to validate source entry Signed-off-by: Josh --- .../Files/Cache/MoveFromCacheTrait.php | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/private/Files/Cache/MoveFromCacheTrait.php b/lib/private/Files/Cache/MoveFromCacheTrait.php index a13e0d7d00e89..564d286aeda5a 100644 --- a/lib/private/Files/Cache/MoveFromCacheTrait.php +++ b/lib/private/Files/Cache/MoveFromCacheTrait.php @@ -11,34 +11,41 @@ use OCP\Files\Cache\ICacheEntry; /** - * Fallback implementation for moveFromCache + * Generic fallback implementation for moving cache entries. + * + * This fallback copies the source entry to the target path and then removes + * it from the source cache. + * + * It is intended for cache implementations that do not provide a specialized + * in-place move operation. */ trait MoveFromCacheTrait { - /** - * store meta data for a file or folder - * - * @param string $file - * @param array $data - * - * @return int file id - * @throws \RuntimeException - */ + abstract public function put($file, array $data); abstract public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, string $targetPath): int; /** - * Move a file or folder in the cache + * Move a file or folder in the cache. + * + * This fallback performs the move as a copy-then-delete, so it does not + * preserve the original cache entry identity and may result in a new file id + * at the destination. * * @param ICache $sourceCache * @param string $sourcePath * @param string $targetPath + * @throws \RuntimeException if the source entry cannot be copied */ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { $sourceEntry = $sourceCache->get($sourcePath); - $this->copyFromCache($sourceCache, $sourceEntry, $targetPath); + if (!$sourceEntry) { + throw new \RuntimeException('Source path not found in cache: ' . $sourcePath); + } + $this->copyFromCache($sourceCache, $sourceEntry, $targetPath); + // non-atomic; failed removals can leave duplicates $sourceCache->remove($sourcePath); } } From c1ec62ce1ef551ea4104a88bf5cca96b0a9a2b32 Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 26 Apr 2026 10:07:01 -0400 Subject: [PATCH 2/2] chore(files/cache): fixup MoveFromCacheTrait::moveFromCache docblock Signed-off-by: Josh --- lib/private/Files/Cache/MoveFromCacheTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Files/Cache/MoveFromCacheTrait.php b/lib/private/Files/Cache/MoveFromCacheTrait.php index 564d286aeda5a..47dcc5738b9fe 100644 --- a/lib/private/Files/Cache/MoveFromCacheTrait.php +++ b/lib/private/Files/Cache/MoveFromCacheTrait.php @@ -35,7 +35,7 @@ abstract public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceE * @param ICache $sourceCache * @param string $sourcePath * @param string $targetPath - * @throws \RuntimeException if the source entry cannot be copied + * @throws \RuntimeException if the source path cannot be found in cache */ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { $sourceEntry = $sourceCache->get($sourcePath);