Skip to content

Commit f77ae68

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 27dc120 commit f77ae68

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

apps/files/lib/Listener/SyncLivePhotosListener.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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,6 +155,12 @@ private function handleCopy(File $sourceFile, File $targetFile, File $peerFile):
153155
$targetName = $targetFile->getName();
154156
$peerTargetName = substr($targetName, 0, -strlen($sourceExtension)) . $peerFileExtension;
155157

158+
// in case the copy was initiated from this listener, we stop right now
159+
if (in_array($peerFile->getId(), $this->pendingCopies)) {
160+
return;
161+
}
162+
163+
$this->pendingCopies[] = $sourceFile->getId();
156164

157165
if ($targetParent->nodeExists($peerTargetName)) {
158166
// If the copy was a folder copy, then the peer file already exists.
@@ -172,6 +180,8 @@ private function handleCopy(File $sourceFile, File $targetFile, File $peerFile):
172180
$peerMetadata->setStorageId($targetPeerFile->getStorage()->getCache()->getNumericStorageId());
173181
$peerMetadata->setString('files-live-photo', (string)$targetFile->getId());
174182
$this->filesMetadataManager->saveMetadata($peerMetadata);
183+
184+
$this->pendingCopies = array_diff($this->pendingCopies, [$sourceFile->getId()]);
175185
}
176186

177187
/**

0 commit comments

Comments
 (0)