Skip to content

Commit 9a2a2b1

Browse files
authored
Merge pull request #53159 from nextcloud/backport/52996/stable31
[stable31] fix(node): emit hooks on `Node::copy()`
2 parents 4d033ed + 6bca885 commit 9a2a2b1

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

apps/files/lib/Listener/SyncLivePhotosListener.php

Lines changed: 9 additions & 1 deletion
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,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
}

lib/private/Files/View.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ public function copy($source, $target, $preserveMtime = false) {
937937

938938
try {
939939
$exists = $this->file_exists($target);
940-
if ($this->shouldEmitHooks()) {
940+
if ($this->shouldEmitHooks($target)) {
941941
\OC_Hook::emit(
942942
Filesystem::CLASSNAME,
943943
Filesystem::signal_copy,
@@ -977,7 +977,7 @@ public function copy($source, $target, $preserveMtime = false) {
977977
$this->changeLock($target, ILockingProvider::LOCK_SHARED);
978978
$lockTypePath2 = ILockingProvider::LOCK_SHARED;
979979

980-
if ($this->shouldEmitHooks() && $result !== false) {
980+
if ($this->shouldEmitHooks($target) && $result !== false) {
981981
\OC_Hook::emit(
982982
Filesystem::CLASSNAME,
983983
Filesystem::signal_post_copy,

0 commit comments

Comments
 (0)