Skip to content
Merged
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
fix: redirect to proper directory if file not found
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
  • Loading branch information
skjnldsv committed Oct 4, 2023
commit b05719c8e900268a50412756c38ee19a87e67093
15 changes: 14 additions & 1 deletion apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,19 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
$favElements['folders'] = [];
}

// If the file doesn't exists in the folder and
// exists in only one occurrence, redirect to that file
// in the correct folder
if ($fileid && $dir !== '') {
$baseFolder = $this->rootFolder->getUserFolder($userId);
$nodes = $baseFolder->getById((int) $fileid);
$relativePath = dirname($baseFolder->getRelativePath($nodes[0]->getPath()));

Check notice

Code scanning / Psalm

PossiblyNullArgument

Argument 1 of dirname cannot be null, possibly null value provided
// If the requested path is different from the file path
if (count($nodes) === 1 && $relativePath !== $dir) {
return $this->redirectToFile((int) $fileid);
}
}

try {
// If view is files, we use the directory, otherwise we use the root storage
$storageInfo = $this->getStorageInfo(($view === 'files' && $dir) ? $dir : '/');
Expand Down Expand Up @@ -380,7 +393,7 @@ private function redirectToFile(int $fileId) {
$uid = $this->userSession->getUser()->getUID();
$baseFolder = $this->rootFolder->getUserFolder($uid);
$nodes = $baseFolder->getById($fileId);
$params = [];
$params = ['view' => 'files'];

try {
$this->redirectToFileIfInTrashbin($fileId);
Expand Down