1515use OC \Files \Node \Folder ;
1616use OC \Files \Node \NonExistingFile ;
1717use OC \Files \Node \NonExistingFolder ;
18- use OC \Files \ObjectStore \ObjectStoreStorage ;
1918use OC \Files \View ;
2019use OC_User ;
2120use OCA \Files_Trashbin \AppInfo \Application ;
3029use OCP \Files \NotFoundException ;
3130use OCP \Files \NotPermittedException ;
3231use OCP \Files \Storage \ILockingStorage ;
32+ use OCP \Files \Storage \IStorage ;
3333use OCP \FilesMetadata \IFilesMetadataManager ;
3434use OCP \IConfig ;
3535use OCP \IDBConnection ;
@@ -256,11 +256,10 @@ public static function move2trash($file_path, $ownerOnly = false) {
256256 $ trashPath = '/files_trashbin/files/ ' . static ::getTrashFilename ($ filename , $ timestamp );
257257 $ gotLock = false ;
258258
259- while (!$ gotLock ) {
259+ do {
260+ /** @var ILockingStorage & IStorage $trashStorage */
261+ [$ trashStorage , $ trashInternalPath ] = $ ownerView ->resolvePath ($ trashPath );
260262 try {
261- /** @var ILockingStorage $trashStorage */
262- [$ trashStorage , $ trashInternalPath ] = $ ownerView ->resolvePath ($ trashPath );
263-
264263 $ trashStorage ->acquireLock ($ trashInternalPath , ILockingProvider::LOCK_EXCLUSIVE , $ lockingProvider );
265264 $ gotLock = true ;
266265 } catch (LockedException $ e ) {
@@ -271,7 +270,7 @@ public static function move2trash($file_path, $ownerOnly = false) {
271270
272271 $ trashPath = '/files_trashbin/files/ ' . static ::getTrashFilename ($ filename , $ timestamp );
273272 }
274- }
273+ } while (! $ gotLock );
275274
276275 $ sourceStorage = $ sourceInfo ->getStorage ();
277276 $ sourceInternalPath = $ sourceInfo ->getInternalPath ();
@@ -285,14 +284,12 @@ public static function move2trash($file_path, $ownerOnly = false) {
285284 return false ;
286285 }
287286
288- $ trashStorage ->getUpdater ()->renameFromStorage ($ sourceStorage , $ sourceInternalPath , $ trashInternalPath );
289-
290287 try {
291288 $ moveSuccessful = true ;
292289
293- // when moving within the same object store, the cache update done above is enough to move the file
294- if (!( $ trashStorage -> instanceOfStorage (ObjectStoreStorage::class) && $ trashStorage -> getId () === $ sourceStorage -> getId () )) {
295- $ trashStorage ->moveFromStorage ($ sourceStorage , $ sourceInternalPath , $ trashInternalPath );
290+ $ trashStorage -> moveFromStorage ( $ sourceStorage , $ sourceInternalPath , $ trashInternalPath );
291+ if ($ sourceStorage -> getCache ()-> inCache ( $ sourceInternalPath )) {
292+ $ trashStorage ->getUpdater ()-> renameFromStorage ($ sourceStorage , $ sourceInternalPath , $ trashInternalPath );
296293 }
297294 } catch (\OCA \Files_Trashbin \Exceptions \CopyRecursiveException $ e ) {
298295 $ moveSuccessful = false ;
0 commit comments