Skip to content

Commit 185fe53

Browse files
authored
Merge pull request #36893 from nextcloud/fix/avoid-file-events-on-null-path
Make sure to never trigger files hooks on a null path
2 parents 20edd4b + 6034cc6 commit 185fe53

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

apps/dav/lib/Connector/Sabre/File.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,15 @@ private function getPartFileBasePath($path) {
422422
}
423423
}
424424

425-
/**
426-
* @param string $path
427-
*/
428-
private function emitPreHooks($exists, $path = null) {
425+
private function emitPreHooks(bool $exists, ?string $path = null): bool {
429426
if (is_null($path)) {
430427
$path = $this->path;
431428
}
432429
$hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path));
430+
if ($hookPath === null) {
431+
// We only trigger hooks from inside default view
432+
return true;
433+
}
433434
$run = true;
434435

435436
if (!$exists) {
@@ -450,14 +451,15 @@ private function emitPreHooks($exists, $path = null) {
450451
return $run;
451452
}
452453

453-
/**
454-
* @param string $path
455-
*/
456-
private function emitPostHooks($exists, $path = null) {
454+
private function emitPostHooks(bool $exists, ?string $path = null): void {
457455
if (is_null($path)) {
458456
$path = $this->path;
459457
}
460458
$hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path));
459+
if ($hookPath === null) {
460+
// We only trigger hooks from inside default view
461+
return;
462+
}
461463
if (!$exists) {
462464
\OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_create, [
463465
\OC\Files\Filesystem::signal_param_path => $hookPath

lib/private/Files/Node/HookConnector.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/**
36
* @copyright Copyright (c) 2016, ownCloud, Inc.
47
*
@@ -223,7 +226,7 @@ public function read($arguments) {
223226
$this->dispatcher->dispatchTyped($event);
224227
}
225228

226-
private function getNodeForPath($path) {
229+
private function getNodeForPath(string $path): Node {
227230
$info = Filesystem::getView()->getFileInfo($path);
228231
if (!$info) {
229232
$fullPath = Filesystem::getView()->getAbsolutePath($path);

0 commit comments

Comments
 (0)