|
12 | 12 | use OCP\Files\Cache\ICacheEntry; |
13 | 13 |
|
14 | 14 | /** |
15 | | - * Fallback implementation for moveFromCache |
| 15 | + * Generic fallback implementation for moving cache entries. |
| 16 | + * |
| 17 | + * This fallback copies the source entry to the target path and then removes |
| 18 | + * it from the source cache. |
| 19 | + * |
| 20 | + * It is intended for cache implementations that do not provide a specialized |
| 21 | + * in-place move operation. |
16 | 22 | */ |
17 | 23 | trait MoveFromCacheTrait { |
18 | | - /** |
19 | | - * store meta data for a file or folder |
20 | | - * |
21 | | - * @param string $file |
22 | | - * @param array $data |
23 | | - * |
24 | | - * @return int file id |
25 | | - * @throws \RuntimeException |
26 | | - */ |
| 24 | + |
27 | 25 | abstract public function put($file, array $data); |
28 | 26 |
|
29 | 27 | abstract public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, string $targetPath): int; |
30 | 28 |
|
31 | 29 | /** |
32 | | - * Move a file or folder in the cache |
| 30 | + * Move a file or folder in the cache. |
| 31 | + * |
| 32 | + * This fallback performs the move as a copy-then-delete, so it does not |
| 33 | + * preserve the original cache entry identity and may result in a new file id |
| 34 | + * at the destination. |
33 | 35 | * |
34 | 36 | * @param ICache $sourceCache |
35 | 37 | * @param string $sourcePath |
36 | 38 | * @param string $targetPath |
| 39 | + * @throws \RuntimeException if the source path cannot be found in cache |
37 | 40 | */ |
38 | 41 | public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
39 | 42 | $sourceEntry = $sourceCache->get($sourcePath); |
40 | 43 |
|
41 | | - $this->copyFromCache($sourceCache, $sourceEntry, $targetPath); |
| 44 | + if (!$sourceEntry) { |
| 45 | + throw new \RuntimeException('Source path not found in cache: ' . $sourcePath); |
| 46 | + } |
42 | 47 |
|
| 48 | + $this->copyFromCache($sourceCache, $sourceEntry, $targetPath); |
| 49 | + // non-atomic; failed removals can leave duplicates |
43 | 50 | $sourceCache->remove($sourcePath); |
44 | 51 | } |
45 | 52 | } |
0 commit comments