@@ -37,6 +37,8 @@ class SyncLivePhotosListener implements IEventListener {
3737 private array $ pendingRenames = [];
3838 /** @var Array<int, bool> */
3939 private array $ pendingDeletion = [];
40+ /** @var Array<int> */
41+ private array $ pendingCopies = [];
4042
4143 public function __construct (
4244 private ?Folder $ userFolder ,
@@ -153,7 +155,6 @@ private function handleCopy(File $sourceFile, File $targetFile, File $peerFile):
153155 $ targetName = $ targetFile ->getName ();
154156 $ peerTargetName = substr ($ targetName , 0 , -strlen ($ sourceExtension )) . $ peerFileExtension ;
155157
156-
157158 if ($ targetParent ->nodeExists ($ peerTargetName )) {
158159 // If the copy was a folder copy, then the peer file already exists.
159160 $ targetPeerFile = $ targetParent ->get ($ peerTargetName );
@@ -225,6 +226,11 @@ private function handleCopyRecursive(Event $event, Node $sourceNode, Node $targe
225226 $ this ->handleCopyRecursive ($ event , $ sourceChild , $ targetChild );
226227 }
227228 } 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+
228234 $ peerFileId = $ this ->livePhotosService ->getLivePhotoPeerId ($ sourceNode ->getId ());
229235 if ($ peerFileId === null ) {
230236 return ;
@@ -234,11 +240,13 @@ private function handleCopyRecursive(Event $event, Node $sourceNode, Node $targe
234240 return ;
235241 }
236242
243+ $ this ->pendingCopies [] = $ peerFileId ;
237244 if ($ event instanceof BeforeNodeCopiedEvent) {
238245 $ this ->runMoveOrCopyChecks ($ sourceNode , $ targetNode , $ peerFile );
239246 } elseif ($ event instanceof NodeCopiedEvent) {
240247 $ this ->handleCopy ($ sourceNode , $ targetNode , $ peerFile );
241248 }
249+ $ this ->pendingCopies = array_diff ($ this ->pendingCopies , [$ peerFileId ]);
242250 } else {
243251 throw new Exception ('Source and target type are not matching ' );
244252 }
0 commit comments