Skip to content
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

fix: Drop unnecessary exit #48145

Merged
merged 6 commits into from
Sep 18, 2024
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
1 change: 0 additions & 1 deletion apps/dav/lib/Files/ErrorPagePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public function generateBody(\Throwable $ex, int $httpCode): mixed {
*/
public function sendResponse() {
$this->server->sapi->sendResponse($this->server->httpResponse);
exit();
}

private function acceptHtml(): bool {
Expand Down
15 changes: 1 addition & 14 deletions core/templates/exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,7 @@

style('core', ['styles', 'header', 'exception']);

function print_exception(Throwable $e, \OCP\IL10N $l): void {
print_unescaped('<pre>');
p($e->getTraceAsString());
print_unescaped('</pre>');

if ($e->getPrevious() !== null) {
print_unescaped('<br />');
print_unescaped('<h4>');
p($l->t('Previous'));
print_unescaped('</h4>');

print_exception($e->getPrevious(), $l);
}
}
require_once __DIR__ . '/print_exception.php';

?>
<div class="guest-box wide">
Expand Down
21 changes: 21 additions & 0 deletions core/templates/print_exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2012-2015 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/

function print_exception(Throwable $e, \OCP\IL10N $l): void {
print_unescaped('<pre>');
p($e->getTraceAsString());
print_unescaped('</pre>');

if ($e->getPrevious() !== null) {
print_unescaped('<br />');
print_unescaped('<h4>');
p($l->t('Previous'));
print_unescaped('</h4>');

print_exception($e->getPrevious(), $l);
}
}
16 changes: 16 additions & 0 deletions core/templates/print_xml_exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2012-2015 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/

function print_exception(Throwable $e, \OCP\IL10N $l): void {
p($e->getTraceAsString());

if ($e->getPrevious() !== null) {
print_unescaped('<s:previous-exception>');
print_exception($e->getPrevious(), $l);
print_unescaped('</s:previous-exception>');
}
}
10 changes: 1 addition & 9 deletions core/templates/xml_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/

function print_exception(Throwable $e, \OCP\IL10N $l): void {
p($e->getTraceAsString());

if ($e->getPrevious() !== null) {
print_unescaped('<s:previous-exception>');
print_exception($e->getPrevious(), $l);
print_unescaped('</s:previous-exception>');
}
}
require_once __DIR__ . '/print_xml_exception.php';

print_unescaped('<?xml version="1.0" encoding="utf-8"?>' . "\n");
?>
Expand Down
25 changes: 22 additions & 3 deletions tests/lib/Files/Node/FolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ public function testSearchInRoot(): void {

$storage->method('getCache')
->willReturn($cache);
$storage->method('getOwner')
->willReturn('owner');

$cache->insert('files', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$cache->insert('files/foo', ['size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']);
Expand Down Expand Up @@ -391,6 +393,8 @@ public function testSearchInStorageRoot(): void {

$storage->method('getCache')
->willReturn($cache);
$storage->method('getOwner')
->willReturn('owner');

$cache->insert('foo', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$cache->insert('foo/qwerty', ['size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']);
Expand Down Expand Up @@ -442,9 +446,13 @@ public function testSearchSubStorages(): void {

$storage->method('getCache')
->willReturn($cache);
$storage->method('getOwner')
->willReturn('owner');

$subStorage->method('getCache')
->willReturn($subCache);
$subStorage->method('getOwner')
->willReturn('owner');

$cache->insert('foo', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$cache->insert('foo/qwerty', ['size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']);
Expand Down Expand Up @@ -496,6 +504,8 @@ public function testGetById(): void {

$storage->method('getCache')
->willReturn($cache);
$storage->method('getOwner')
->willReturn('owner');

$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
Expand Down Expand Up @@ -543,6 +553,8 @@ public function testGetByIdMountRoot(): void {

$storage->method('getCache')
->willReturn($cache);
$storage->method('getOwner')
->willReturn('owner');

$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
Expand Down Expand Up @@ -586,6 +598,8 @@ public function testGetByIdOutsideFolder(): void {

$storage->method('getCache')
->willReturn($cache);
$storage->method('getOwner')
->willReturn('owner');

$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
Expand Down Expand Up @@ -629,6 +643,8 @@ public function testGetByIdMultipleStorages(): void {

$storage->method('getCache')
->willReturn($cache);
$storage->method('getOwner')
->willReturn('owner');

$this->userMountCache->method('getMountsForFileId')
->with(1)
Expand All @@ -644,9 +660,6 @@ public function testGetByIdMultipleStorages(): void {
),
]);

$storage->method('getCache')
->willReturn($cache);

$cache->method('get')
->with(1)
->willReturn($fileInfo);
Expand Down Expand Up @@ -948,9 +961,13 @@ public function testSearchSubStoragesLimitOffset(int $offset, int $limit, array

$storage->method('getCache')
->willReturn($cache);
$storage->method('getOwner')
->willReturn('owner');

$subStorage1->method('getCache')
->willReturn($subCache1);
$subStorage1->method('getOwner')
->willReturn('owner');

$subMount2->method('getStorage')
->willReturn($subStorage2);
Expand All @@ -960,6 +977,8 @@ public function testSearchSubStoragesLimitOffset(int $offset, int $limit, array

$subStorage2->method('getCache')
->willReturn($subCache2);
$subStorage2->method('getOwner')
->willReturn('owner');

$cache->insert('foo/foo1', ['size' => 200, 'mtime' => 10, 'mimetype' => 'text/plain']);
$cache->insert('foo/foo2', ['size' => 200, 'mtime' => 20, 'mimetype' => 'text/plain']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Test\Files\ObjectStore;

use OC\Files\ObjectStore\StorageObjectStore;
use OC\Files\Storage\Temporary;
use Test\Files\Storage\StoragesTest;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Test\Files\ObjectStore;

use OC\Files\ObjectStore\StorageObjectStore;
use OC\Files\Storage\Temporary;
use Test\Files\Storage\StoragesTest;

/**
Expand Down
112 changes: 56 additions & 56 deletions tests/lib/Files/Storage/StoragesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,76 +33,76 @@ protected function tearDown(): void {
public function testMoveFileFromStorage() {
$source = 'source.txt';
$target = 'target.txt';
$storage2->file_put_contents($source, 'foo');
$this->storage2->file_put_contents($source, 'foo');

$storage1->moveFromStorage($storage2, $source, $target);
$this->storage1->moveFromStorage($this->storage2, $source, $target);

$this->assertTrue($storage1->file_exists($target), $target.' was not created');
$this->assertFalse($storage2->file_exists($source), $source.' still exists');
$this->assertEquals('foo', $storage1->file_get_contents($target));
$this->assertTrue($this->storage1->file_exists($target), $target.' was not created');
$this->assertFalse($this->storage2->file_exists($source), $source.' still exists');
$this->assertEquals('foo', $this->storage1->file_get_contents($target));
}

public function testMoveDirectoryFromStorage() {
$storage2->mkdir('source');
$storage2->file_put_contents('source/test1.txt', 'foo');
$storage2->file_put_contents('source/test2.txt', 'qwerty');
$storage2->mkdir('source/subfolder');
$storage2->file_put_contents('source/subfolder/test.txt', 'bar');

$storage1->moveFromStorage($storage2, 'source', 'target');

$this->assertTrue($storage1->file_exists('target'));
$this->assertTrue($storage1->file_exists('target/test1.txt'));
$this->assertTrue($storage1->file_exists('target/test2.txt'));
$this->assertTrue($storage1->file_exists('target/subfolder'));
$this->assertTrue($storage1->file_exists('target/subfolder/test.txt'));

$this->assertFalse($storage2->file_exists('source'));
$this->assertFalse($storage2->file_exists('source/test1.txt'));
$this->assertFalse($storage2->file_exists('source/test2.txt'));
$this->assertFalse($storage2->file_exists('source/subfolder'));
$this->assertFalse($storage2->file_exists('source/subfolder/test.txt'));

$this->assertEquals('foo', $storage1->file_get_contents('target/test1.txt'));
$this->assertEquals('qwerty', $storage1->file_get_contents('target/test2.txt'));
$this->assertEquals('bar', $storage1->file_get_contents('target/subfolder/test.txt'));
$this->storage2->mkdir('source');
$this->storage2->file_put_contents('source/test1.txt', 'foo');
$this->storage2->file_put_contents('source/test2.txt', 'qwerty');
$this->storage2->mkdir('source/subfolder');
$this->storage2->file_put_contents('source/subfolder/test.txt', 'bar');

$this->storage1->moveFromStorage($this->storage2, 'source', 'target');

$this->assertTrue($this->storage1->file_exists('target'));
$this->assertTrue($this->storage1->file_exists('target/test1.txt'));
$this->assertTrue($this->storage1->file_exists('target/test2.txt'));
$this->assertTrue($this->storage1->file_exists('target/subfolder'));
$this->assertTrue($this->storage1->file_exists('target/subfolder/test.txt'));

$this->assertFalse($this->storage2->file_exists('source'));
$this->assertFalse($this->storage2->file_exists('source/test1.txt'));
$this->assertFalse($this->storage2->file_exists('source/test2.txt'));
$this->assertFalse($this->storage2->file_exists('source/subfolder'));
$this->assertFalse($this->storage2->file_exists('source/subfolder/test.txt'));

$this->assertEquals('foo', $this->storage1->file_get_contents('target/test1.txt'));
$this->assertEquals('qwerty', $this->storage1->file_get_contents('target/test2.txt'));
$this->assertEquals('bar', $this->storage1->file_get_contents('target/subfolder/test.txt'));
}

public function testCopyFileFromStorage() {
$source = 'source.txt';
$target = 'target.txt';
$storage2->file_put_contents($source, 'foo');
$this->storage2->file_put_contents($source, 'foo');

$storage1->copyFromStorage($storage2, $source, $target);
$this->storage1->copyFromStorage($this->storage2, $source, $target);

$this->assertTrue($storage1->file_exists($target), $target.' was not created');
$this->assertTrue($storage2->file_exists($source), $source.' was deleted');
$this->assertEquals('foo', $storage1->file_get_contents($target));
$this->assertTrue($this->storage1->file_exists($target), $target.' was not created');
$this->assertTrue($this->storage2->file_exists($source), $source.' was deleted');
$this->assertEquals('foo', $this->storage1->file_get_contents($target));
}

public function testCopyDirectoryFromStorage() {
$storage2->mkdir('source');
$storage2->file_put_contents('source/test1.txt', 'foo');
$storage2->file_put_contents('source/test2.txt', 'qwerty');
$storage2->mkdir('source/subfolder');
$storage2->file_put_contents('source/subfolder/test.txt', 'bar');

$storage1->copyFromStorage($storage2, 'source', 'target');

$this->assertTrue($storage1->file_exists('target'));
$this->assertTrue($storage1->file_exists('target/test1.txt'));
$this->assertTrue($storage1->file_exists('target/test2.txt'));
$this->assertTrue($storage1->file_exists('target/subfolder'));
$this->assertTrue($storage1->file_exists('target/subfolder/test.txt'));

$this->assertTrue($storage2->file_exists('source'));
$this->assertTrue($storage2->file_exists('source/test1.txt'));
$this->assertTrue($storage2->file_exists('source/test2.txt'));
$this->assertTrue($storage2->file_exists('source/subfolder'));
$this->assertTrue($storage2->file_exists('source/subfolder/test.txt'));

$this->assertEquals('foo', $storage1->file_get_contents('target/test1.txt'));
$this->assertEquals('qwerty', $storage1->file_get_contents('target/test2.txt'));
$this->assertEquals('bar', $storage1->file_get_contents('target/subfolder/test.txt'));
$this->storage2->mkdir('source');
$this->storage2->file_put_contents('source/test1.txt', 'foo');
$this->storage2->file_put_contents('source/test2.txt', 'qwerty');
$this->storage2->mkdir('source/subfolder');
$this->storage2->file_put_contents('source/subfolder/test.txt', 'bar');

$this->storage1->copyFromStorage($this->storage2, 'source', 'target');

$this->assertTrue($this->storage1->file_exists('target'));
$this->assertTrue($this->storage1->file_exists('target/test1.txt'));
$this->assertTrue($this->storage1->file_exists('target/test2.txt'));
$this->assertTrue($this->storage1->file_exists('target/subfolder'));
$this->assertTrue($this->storage1->file_exists('target/subfolder/test.txt'));

$this->assertTrue($this->storage2->file_exists('source'));
$this->assertTrue($this->storage2->file_exists('source/test1.txt'));
$this->assertTrue($this->storage2->file_exists('source/test2.txt'));
$this->assertTrue($this->storage2->file_exists('source/subfolder'));
$this->assertTrue($this->storage2->file_exists('source/subfolder/test.txt'));

$this->assertEquals('foo', $this->storage1->file_get_contents('target/test1.txt'));
$this->assertEquals('qwerty', $this->storage1->file_get_contents('target/test2.txt'));
$this->assertEquals('bar', $this->storage1->file_get_contents('target/subfolder/test.txt'));
}
}
17 changes: 14 additions & 3 deletions tests/lib/Repair/RepairMimeTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
namespace Test\Repair;

use OC\Files\Storage\Temporary;
use OC\Repair\RepairMimeTypes;
use OCP\Files\IMimeTypeLoader;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;

Expand Down Expand Up @@ -42,13 +45,21 @@ protected function setUp(): void {
$config->method('getSystemValueString')
->with('version')
->willReturn('11.0.0.0');
$config->method('getAppValue')

$appConfig = $this->getMockBuilder(IAppConfig::class)
->disableOriginalConstructor()
->getMock();
$appConfig->method('getValueString')
->with('files', 'mimetype_version')
->willReturn('11.0.0.0');

$this->storage = new \OC\Files\Storage\Temporary([]);
$this->storage = new Temporary([]);

$this->repair = new \OC\Repair\RepairMimeTypes($config, \OC::$server->getDatabaseConnection());
$this->repair = new RepairMimeTypes(
$config,
$appConfig,
\OCP\Server::get(IDBConnection::class),
);
}

protected function tearDown(): void {
Expand Down
Loading
Loading