]> source.dussan.org Git - nextcloud-server.git/commitdiff
Make sure to never trigger files hooks on a null path 38204/head
authorCôme Chilliet <come.chilliet@nextcloud.com>
Tue, 28 Feb 2023 11:16:37 +0000 (12:16 +0100)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Thu, 11 May 2023 14:43:04 +0000 (14:43 +0000)
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
apps/dav/lib/Connector/Sabre/File.php
lib/private/Files/Node/HookConnector.php

index b0f17417d21951d1f7496dcc87737f4781e3f899..a7cafeb4a5e1aed20b6c519fe3373a95a120cb65 100644 (file)
@@ -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
index 149ffafd46b5db7c5c091dfe75c65bf7d7c8adfc..c61e098c22771a749e4650f6a9afbc04ba69bce8 100644 (file)
@@ -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);