Merge pull request #36893 from nextcloud/fix/avoid-file-events-on-null-path

Make sure to never trigger files hooks on a null path
pull/38048/head
Côme Chilliet 2023-05-09 17:44:14 +07:00 committed by GitHub
commit 185fe5378b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

@ -422,14 +422,15 @@ class File extends Node implements IFile {
}
}
/**
* @param string $path
*/
private function emitPreHooks($exists, $path = null) {
private function emitPreHooks(bool $exists, ?string $path = null): bool {
if (is_null($path)) {
$path = $this->path;
}
$hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path));
if ($hookPath === null) {
// We only trigger hooks from inside default view
return true;
}
$run = true;
if (!$exists) {
@ -450,14 +451,15 @@ class File extends Node implements IFile {
return $run;
}
/**
* @param string $path
*/
private function emitPostHooks($exists, $path = null) {
private function emitPostHooks(bool $exists, ?string $path = null): void {
if (is_null($path)) {
$path = $this->path;
}
$hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path));
if ($hookPath === null) {
// We only trigger hooks from inside default view
return;
}
if (!$exists) {
\OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_create, [
\OC\Files\Filesystem::signal_param_path => $hookPath

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@ -223,7 +226,7 @@ class HookConnector {
$this->dispatcher->dispatchTyped($event);
}
private function getNodeForPath($path) {
private function getNodeForPath(string $path): Node {
$info = Filesystem::getView()->getFileInfo($path);
if (!$info) {
$fullPath = Filesystem::getView()->getAbsolutePath($path);