99
1010use Doctrine \DBAL \Exception \DeadlockException ;
1111use OC \Files \FileInfo ;
12+ use OC \Files \ObjectStore \ObjectStoreStorage ;
13+ use OCP \Files \Cache \ICache ;
1214use OCP \Files \Cache \ICacheEntry ;
1315use OCP \Files \Cache \IUpdater ;
1416use OCP \Files \Storage \IStorage ;
@@ -157,13 +159,40 @@ public function remove($path) {
157159 }
158160
159161 /**
160- * Rename a file or folder in the cache and update the size, etag and mtime of the parent folders
162+ * Rename a file or folder in the cache.
161163 *
162164 * @param IStorage $sourceStorage
163165 * @param string $source
164166 * @param string $target
165167 */
166168 public function renameFromStorage (IStorage $ sourceStorage , $ source , $ target ) {
169+ $ this ->copyOrRenameFromStorage ($ sourceStorage , $ source , $ target , function (ICache $ sourceCache ) use ($ sourceStorage , $ source , $ target ) {
170+ // Remove existing cache entry to no reuse the fileId.
171+ if ($ this ->cache ->inCache ($ target )) {
172+ $ this ->cache ->remove ($ target );
173+ }
174+
175+ if ($ sourceStorage === $ this ->storage ) {
176+ $ this ->cache ->move ($ source , $ target );
177+ } else {
178+ $ this ->cache ->moveFromCache ($ sourceCache , $ source , $ target );
179+ }
180+ });
181+ }
182+
183+ /**
184+ * Copy a file or folder in the cache.
185+ */
186+ public function copyFromStorage (IStorage $ sourceStorage , string $ source , string $ target ): void {
187+ $ this ->copyOrRenameFromStorage ($ sourceStorage , $ source , $ target , function (ICache $ sourceCache , ICacheEntry $ sourceInfo ) use ($ target ) {
188+ $ this ->cache ->copyFromCache ($ sourceCache , $ sourceInfo , $ target );
189+ });
190+ }
191+
192+ /**
193+ * Utility to copy or rename a file or folder in the cache and update the size, etag and mtime of the parent folders
194+ */
195+ private function copyOrRenameFromStorage (IStorage $ sourceStorage , string $ source , string $ target , callable $ operation ): void {
167196 if (!$ this ->enabled or Scanner::isPartialFile ($ source ) or Scanner::isPartialFile ($ target )) {
168197 return ;
169198 }
@@ -177,14 +206,8 @@ public function renameFromStorage(IStorage $sourceStorage, $source, $target) {
177206 $ sourceInfo = $ sourceCache ->get ($ source );
178207
179208 if ($ sourceInfo !== false ) {
180- if ($ this ->cache ->inCache ($ target )) {
181- $ this ->cache ->remove ($ target );
182- }
183-
184- if ($ sourceStorage === $ this ->storage ) {
185- $ this ->cache ->move ($ source , $ target );
186- } else {
187- $ this ->cache ->moveFromCache ($ sourceCache , $ source , $ target );
209+ if (!$ this ->storage ->instanceOfStorage (ObjectStoreStorage::class)) {
210+ $ operation ($ sourceCache , $ sourceInfo );
188211 }
189212
190213 $ sourceExtension = pathinfo ($ source , PATHINFO_EXTENSION );
0 commit comments