@@ -37,6 +37,8 @@ class SyncLivePhotosListener implements IEventListener {
37
37
private array $ pendingRenames = [];
38
38
/** @var Array<int, bool> */
39
39
private array $ pendingDeletion = [];
40
+ /** @var Array<int> */
41
+ private array $ pendingCopies = [];
40
42
41
43
public function __construct (
42
44
private ?Folder $ userFolder ,
@@ -153,7 +155,6 @@ private function handleCopy(File $sourceFile, File $targetFile, File $peerFile):
153
155
$ targetName = $ targetFile ->getName ();
154
156
$ peerTargetName = substr ($ targetName , 0 , -strlen ($ sourceExtension )) . $ peerFileExtension ;
155
157
156
-
157
158
if ($ targetParent ->nodeExists ($ peerTargetName )) {
158
159
// If the copy was a folder copy, then the peer file already exists.
159
160
$ targetPeerFile = $ targetParent ->get ($ peerTargetName );
@@ -225,6 +226,11 @@ private function handleCopyRecursive(Event $event, Node $sourceNode, Node $targe
225
226
$ this ->handleCopyRecursive ($ event , $ sourceChild , $ targetChild );
226
227
}
227
228
} elseif ($ sourceNode instanceof File && $ targetNode instanceof File) {
229
+ // in case the copy was initiated from this listener, we stop right now
230
+ if (in_array ($ sourceNode ->getId (), $ this ->pendingCopies )) {
231
+ return ;
232
+ }
233
+
228
234
$ peerFileId = $ this ->livePhotosService ->getLivePhotoPeerId ($ sourceNode ->getId ());
229
235
if ($ peerFileId === null ) {
230
236
return ;
@@ -234,11 +240,13 @@ private function handleCopyRecursive(Event $event, Node $sourceNode, Node $targe
234
240
return ;
235
241
}
236
242
243
+ $ this ->pendingCopies [] = $ peerFileId ;
237
244
if ($ event instanceof BeforeNodeCopiedEvent) {
238
245
$ this ->runMoveOrCopyChecks ($ sourceNode , $ targetNode , $ peerFile );
239
246
} elseif ($ event instanceof NodeCopiedEvent) {
240
247
$ this ->handleCopy ($ sourceNode , $ targetNode , $ peerFile );
241
248
}
249
+ $ this ->pendingCopies = array_diff ($ this ->pendingCopies , [$ peerFileId ]);
242
250
} else {
243
251
throw new Exception ('Source and target type are not matching ' );
244
252
}
0 commit comments