@@ -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$ targetFilegetName ();
154156		$ peerTargetNamesubstr ($ targetName0 , -strlen ($ sourceExtension$ peerFileExtension
155157
156- 
157158		if  ($ targetParentnodeExists ($ peerTargetName
158159			// If the copy was a folder copy, then the peer file already exists. 
159160			$ targetPeerFile$ targetParentget ($ peerTargetName
@@ -225,6 +226,11 @@ private function handleCopyRecursive(Event $event, Node $sourceNode, Node $targe
225226				$ this handleCopyRecursive ($ event$ sourceChild$ targetChild
226227			}
227228		} elseif  ($ sourceNodeinstanceof  File && $ targetNodeinstanceof  File) {
229+ 			// in case the copy was initiated from this listener, we stop right now 
230+ 			if  (in_array ($ sourceNodegetId (), $ this pendingCopies )) {
231+ 				return ;
232+ 			}
233+ 
228234			$ peerFileId$ this livePhotosService ->getLivePhotoPeerId ($ sourceNodegetId ());
229235			if  ($ peerFileIdnull ) {
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  ($ eventinstanceof  BeforeNodeCopiedEvent) {
238245				$ this runMoveOrCopyChecks ($ sourceNode$ targetNode$ peerFile
239246			} elseif  ($ eventinstanceof  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