Skip to content

Commit 1dd0ec8

Browse files
committed
fix(SyncLivePhotosListener): Don't handle copy event emitted from us
Running $peerFile->copy() causes a second BeforeNodeCopiedEvent now, which we don't want to handle. Signed-off-by: Jonas <jonas@freesources.org>
1 parent bf67d8f commit 1dd0ec8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

apps/files/lib/Listener/SyncLivePhotosListener.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class SyncLivePhotosListener implements IEventListener {
3737
private array $pendingRenames = [];
3838
/** @var Array<int, bool> */
3939
private array $pendingDeletion = [];
40+
private string $copyTargetPath = '';
4041

4142
public function __construct(
4243
private ?Folder $userFolder,
@@ -53,6 +54,10 @@ public function handle(Event $event): void {
5354
}
5455

5556
if ($event instanceof BeforeNodeCopiedEvent || $event instanceof NodeCopiedEvent) {
57+
if ($this->copyTargetPath === $event->getTarget()->getPath()) {
58+
$this->copyTargetPath = '';
59+
return;
60+
}
5661
$this->handleCopyRecursive($event, $event->getSource(), $event->getTarget());
5762
} else {
5863
$peerFileId = null;
@@ -158,8 +163,10 @@ private function handleCopy(File $sourceFile, File $targetFile, File $peerFile):
158163
// If the copy was a folder copy, then the peer file already exists.
159164
$targetPeerFile = $targetParent->get($peerTargetName);
160165
} else {
166+
// Register the target path so we can ignore copy events for this copy.
167+
$this->copyTargetPath = $targetParent->getPath() . '/' . $peerTargetName;
161168
// If the copy was a file copy, then we need to create the peer file.
162-
$targetPeerFile = $peerFile->copy($targetParent->getPath() . '/' . $peerTargetName);
169+
$targetPeerFile = $peerFile->copy($this->copyTargetPath);
163170
}
164171

165172
/** @var FilesMetadata $targetMetadata */

0 commit comments

Comments
 (0)