Merge pull request #48145 from nextcloud/artonge/fix/drop_unecessary_exit

fix: Drop unnecessary exit
This commit is contained in:
Joas Schilling 2024-09-18 10:42:09 +02:00 committed by GitHub
commit cd3256bf54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 134 additions and 191 deletions

View file

@ -92,7 +92,6 @@ class ErrorPagePlugin extends ServerPlugin {
*/
public function sendResponse() {
$this->server->sapi->sendResponse($this->server->httpResponse);
exit();
}
private function acceptHtml(): bool {

View file

@ -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">

View file

@ -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);
}
}

View file

@ -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>');
}
}

View file

@ -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");
?>

View file

@ -353,6 +353,8 @@ class FolderTest extends NodeTest {
$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']);
@ -391,6 +393,8 @@ class FolderTest extends NodeTest {
$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']);
@ -442,9 +446,13 @@ class FolderTest extends NodeTest {
$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']);
@ -496,6 +504,8 @@ class FolderTest extends NodeTest {
$storage->method('getCache')
->willReturn($cache);
$storage->method('getOwner')
->willReturn('owner');
$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
@ -543,6 +553,8 @@ class FolderTest extends NodeTest {
$storage->method('getCache')
->willReturn($cache);
$storage->method('getOwner')
->willReturn('owner');
$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
@ -586,6 +598,8 @@ class FolderTest extends NodeTest {
$storage->method('getCache')
->willReturn($cache);
$storage->method('getOwner')
->willReturn('owner');
$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
@ -629,6 +643,8 @@ class FolderTest extends NodeTest {
$storage->method('getCache')
->willReturn($cache);
$storage->method('getOwner')
->willReturn('owner');
$this->userMountCache->method('getMountsForFileId')
->with(1)
@ -644,9 +660,6 @@ class FolderTest extends NodeTest {
),
]);
$storage->method('getCache')
->willReturn($cache);
$cache->method('get')
->with(1)
->willReturn($fileInfo);
@ -948,9 +961,13 @@ class FolderTest extends NodeTest {
$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);
@ -960,6 +977,8 @@ class FolderTest extends NodeTest {
$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']);

View file

@ -7,6 +7,8 @@
namespace Test\Files\ObjectStore;
use OC\Files\ObjectStore\StorageObjectStore;
use OC\Files\Storage\Temporary;
use Test\Files\Storage\StoragesTest;
/**

View file

@ -7,6 +7,8 @@
namespace Test\Files\ObjectStore;
use OC\Files\ObjectStore\StorageObjectStore;
use OC\Files\Storage\Temporary;
use Test\Files\Storage\StoragesTest;
/**

View file

@ -33,76 +33,76 @@ abstract class StoragesTest extends TestCase {
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');
$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');
$storage1->moveFromStorage($storage2, 'source', 'target');
$this->storage1->moveFromStorage($this->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($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($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->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', $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->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');
$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');
$storage1->copyFromStorage($storage2, 'source', 'target');
$this->storage1->copyFromStorage($this->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($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($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->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', $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->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'));
}
}

View file

@ -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;
@ -42,13 +45,21 @@ class RepairMimeTypesTest extends \Test\TestCase {
$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 {

View file

@ -8,7 +8,6 @@
namespace Test;
use OC\App\AppStore\Fetcher\AppFetcher;
use OC\App\AppStore\Fetcher\CategoryFetcher;
use OCP\Comments\ICommentsManager;
/**
@ -31,118 +30,13 @@ class ServerTest extends \Test\TestCase {
public function dataTestQuery() {
return [
['ActivityManager', '\OC\Activity\Manager'],
['ActivityManager', '\OCP\Activity\IManager'],
['AllConfig', '\OC\AllConfig'],
['AllConfig', '\OCP\IConfig'],
['AppConfig', '\OC\AppConfig'],
['AppConfig', '\OCP\IAppConfig'],
['AppFetcher', AppFetcher::class],
['AppManager', '\OC\App\AppManager'],
['AppManager', '\OCP\App\IAppManager'],
['AsyncCommandBus', '\OC\Command\AsyncBus'],
['AsyncCommandBus', '\OCP\Command\IBus'],
['AvatarManager', '\OC\Avatar\AvatarManager'],
['AvatarManager', '\OCP\IAvatarManager'],
['CategoryFetcher', CategoryFetcher::class],
['CapabilitiesManager', '\OC\CapabilitiesManager'],
['ContactsManager', '\OC\ContactsManager'],
['ContactsManager', '\OCP\Contacts\IManager'],
['ContentSecurityPolicyManager', '\OC\Security\CSP\ContentSecurityPolicyManager'],
['CommentsManager', '\OCP\Comments\ICommentsManager'],
['Crypto', '\OC\Security\Crypto'],
['Crypto', '\OCP\Security\ICrypto'],
['CryptoWrapper', '\OC\Session\CryptoWrapper'],
['CsrfTokenManager', '\OC\Security\CSRF\CsrfTokenManager'],
['DatabaseConnection', '\OC\DB\ConnectionAdapter'],
['DatabaseConnection', '\OCP\IDBConnection'],
['DateTimeFormatter', '\OC\DateTimeFormatter'],
['DateTimeFormatter', '\OCP\IDateTimeFormatter'],
['DateTimeZone', '\OC\DateTimeZone'],
['DateTimeZone', '\OCP\IDateTimeZone'],
['EncryptionFileHelper', '\OC\Encryption\File'],
['EncryptionFileHelper', '\OCP\Encryption\IFile'],
['EncryptionKeyStorage', '\OC\Encryption\Keys\Storage'],
['EncryptionKeyStorage', '\OCP\Encryption\Keys\IStorage'],
['EncryptionManager', '\OC\Encryption\Manager'],
['EncryptionManager', '\OCP\Encryption\IManager'],
['EventLogger', '\OCP\Diagnostics\IEventLogger'],
['GroupManager', '\OC\Group\Manager'],
['GroupManager', '\OCP\IGroupManager'],
['Hasher', '\OC\Security\Hasher'],
['Hasher', '\OCP\Security\IHasher'],
['HttpClientService', '\OC\Http\Client\ClientService'],
['HttpClientService', '\OCP\Http\Client\IClientService'],
['IniWrapper', '\bantu\IniGetWrapper\IniGetWrapper'],
['MimeTypeDetector', '\OCP\Files\IMimeTypeDetector'],
['MimeTypeDetector', '\OC\Files\Type\Detection'],
['JobList', '\OC\BackgroundJob\JobList'],
['JobList', '\OCP\BackgroundJob\IJobList'],
['L10NFactory', '\OC\L10N\Factory'],
['L10NFactory', '\OCP\L10N\IFactory'],
['LockingProvider', '\OCP\Lock\ILockingProvider'],
['Logger', '\OC\Log'],
['Logger', '\OCP\ILogger'],
['Mailer', '\OC\Mail\Mailer'],
['Mailer', '\OCP\Mail\IMailer'],
['MemCacheFactory', '\OC\Memcache\Factory'],
['MemCacheFactory', '\OCP\ICacheFactory'],
['MountConfigManager', '\OC\Files\Config\MountProviderCollection'],
['MountConfigManager', '\OCP\Files\Config\IMountProviderCollection'],
['NavigationManager', '\OC\NavigationManager'],
['NavigationManager', '\OCP\INavigationManager'],
['NotificationManager', '\OC\Notification\Manager'],
['NotificationManager', '\OCP\Notification\IManager'],
['UserCache', '\OC\Cache\File'],
['UserCache', '\OCP\ICache'],
['PreviewManager', '\OC\PreviewManager'],
['PreviewManager', '\OCP\IPreview'],
['QueryLogger', '\OCP\Diagnostics\IQueryLogger'],
['Request', '\OC\AppFramework\Http\Request'],
['Request', '\OCP\IRequest'],
['RootFolder', '\OC\Files\Node\Root'],
['RootFolder', '\OC\Files\Node\Folder'],
['RootFolder', '\OCP\Files\IRootFolder'],
['RootFolder', '\OCP\Files\Folder'],
['Router', '\OCP\Route\IRouter'],
['SecureRandom', '\OC\Security\SecureRandom'],
['SecureRandom', '\OCP\Security\ISecureRandom'],
['ShareManager', '\OC\Share20\Manager'],
['ShareManager', '\OCP\Share\IManager'],
['SystemConfig', '\OC\SystemConfig'],
['URLGenerator', '\OC\URLGenerator'],
['URLGenerator', '\OCP\IURLGenerator'],
['UserManager', '\OC\User\Manager'],
['UserManager', '\OCP\IUserManager'],
['UserSession', '\OC\User\Session'],
['UserSession', '\OCP\IUserSession'],
['TagMapper', '\OC\Tagging\TagMapper'],
['TagMapper', '\OCP\AppFramework\Db\QBMapper'],
['TagManager', '\OC\TagManager'],
['TagManager', '\OCP\ITagManager'],
['TempManager', '\OC\TempManager'],
['TempManager', '\OCP\ITempManager'],
['ThemingDefaults', '\OCA\Theming\ThemingDefaults'],
['TrustedDomainHelper', '\OC\Security\TrustedDomainHelper'],
['SystemTagManager', '\OCP\SystemTag\ISystemTagManager'],
['SystemTagObjectMapper', '\OCP\SystemTag\ISystemTagObjectMapper'],
['\OCP\Activity\IManager', '\OC\Activity\Manager'],
['\OCP\IConfig', '\OC\AllConfig'],
['\OCP\IAppConfig', '\OC\AppConfig'],
[AppFetcher::class, AppFetcher::class],
['\OCP\App\IAppManager', '\OC\App\AppManager'],
['\OCP\Command\IBus', '\OC\Command\AsyncBus'],
['\OCP\IAvatarManager', '\OC\Avatar\AvatarManager'],
];
}