Skip to content

Make sure to never trigger files hooks on a null path #36893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions apps/dav/lib/Connector/Sabre/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,15 @@ private function getPartFileBasePath($path) {
}
}

/**
* @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) {
Expand All @@ -450,14 +451,15 @@ private function emitPreHooks($exists, $path = null) {
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
Expand Down
5 changes: 4 additions & 1 deletion lib/private/Files/Node/HookConnector.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
Expand Down Expand Up @@ -223,7 +226,7 @@ public function read($arguments) {
$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);
Expand Down