diff options
author | Marcel Klehr <mklehr@gmx.net> | 2024-05-10 06:51:41 +0200 |
---|---|---|
committer | Marcel Klehr <mklehr@gmx.net> | 2024-05-14 11:38:41 +0200 |
commit | 19a0aaeb5e71a2431d347dc54b28aeaad4254c2c (patch) | |
tree | fb10b99e8bb57882f09aaf58b736c302424eed4d | |
parent | ec94a672d72720530ffcfce92f9695d8b9a09e27 (diff) | |
download | nextcloud-server-19a0aaeb5e71a2431d347dc54b28aeaad4254c2c.tar.gz nextcloud-server-19a0aaeb5e71a2431d347dc54b28aeaad4254c2c.zip |
fix(TextToImage): Allow leaving the resources open
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
-rw-r--r-- | .htaccess | 4 | ||||
-rw-r--r-- | lib/private/TaskProcessing/Manager.php | 6 | ||||
-rw-r--r-- | tests/lib/TaskProcessing/TaskProcessingTest.php | 17 |
3 files changed, 19 insertions, 8 deletions
diff --git a/.htaccess b/.htaccess index f6474c8dbca..21cff356819 100644 --- a/.htaccess +++ b/.htaccess @@ -108,3 +108,7 @@ AddDefaultCharset utf-8 Options -Indexes +#### DO NOT CHANGE ANYTHING ABOVE THIS LINE #### + +ErrorDocument 403 /index.php/error/403 +ErrorDocument 404 /index.php/error/404 diff --git a/lib/private/TaskProcessing/Manager.php b/lib/private/TaskProcessing/Manager.php index 685ac39ba38..b9259b5a4cd 100644 --- a/lib/private/TaskProcessing/Manager.php +++ b/lib/private/TaskProcessing/Manager.php @@ -284,6 +284,12 @@ class Manager implements IManager { } catch (\RuntimeException $e) { throw new ProcessingException($e->getMessage(), 0, $e); } + for ($i = 0; $i < $input['numberOfImages']; $i++) { + if (is_resource($resources[$i])) { + // If $resource hasn't been closed yet, we'll do that here + fclose($resources[$i]); + } + } return ['images' => array_map(fn (ISimpleFile $file) => $file->getContent(), $files)]; } }; diff --git a/tests/lib/TaskProcessing/TaskProcessingTest.php b/tests/lib/TaskProcessing/TaskProcessingTest.php index 846644ab6c3..ac220ad7c63 100644 --- a/tests/lib/TaskProcessing/TaskProcessingTest.php +++ b/tests/lib/TaskProcessing/TaskProcessingTest.php @@ -256,7 +256,6 @@ class SuccessfulTextToImageProvider implements \OCP\TextToImage\IProvider { $this->ran = true; foreach($resources as $resource) { fwrite($resource, 'test'); - fclose($resource); } } @@ -299,8 +298,8 @@ class TaskProcessingTest extends \Test\TestCase { private TaskMapper $taskMapper; private IJobList $jobList; private IAppData $appData; - private \OCP\Share\IManager $shareManager; + private IRootFolder $rootFolder; protected function setUp(): void { parent::setUp(); @@ -332,6 +331,8 @@ class TaskProcessingTest extends \Test\TestCase { $this->coordinator = $this->createMock(Coordinator::class); $this->coordinator->expects($this->any())->method('getRegistrationContext')->willReturn($this->registrationContext); + $this->rootFolder = \OCP\Server::get(IRootFolder::class); + $this->taskMapper = \OCP\Server::get(TaskMapper::class); $this->jobList = $this->createPartialMock(DummyJobList::class, ['add']); @@ -383,8 +384,6 @@ class TaskProcessingTest extends \Test\TestCase { } private function getFile(string $name, string $content): \OCP\Files\File { - /** @var IRootFolder $rootFolder */ - $rootFolder = \OC::$server->get(IRootFolder::class); $this->appData = \OC::$server->get(IAppDataFactory::class)->get('core'); try { $folder = $this->appData->getFolder('test'); @@ -392,7 +391,7 @@ class TaskProcessingTest extends \Test\TestCase { $folder = $this->appData->newFolder('test'); } $file = $folder->newFile($name, $content); - $inputFile = current($rootFolder->getByIdInPath($file->getId(), '/' . $rootFolder->getAppDataDirectoryName() . '/')); + $inputFile = current($this->rootFolder->getByIdInPath($file->getId(), '/' . $this->rootFolder->getAppDataDirectoryName() . '/')); if (!$inputFile instanceof \OCP\Files\File) { throw new \Exception('PEBCAK'); } @@ -581,12 +580,10 @@ class TaskProcessingTest extends \Test\TestCase { self::assertEquals(Task::STATUS_SUCCESSFUL, $task->getStatus()); self::assertEquals(1, $task->getProgress()); self::assertTrue(isset($task->getOutput()['spectrogram'])); - $root = \OCP\Server::get(IRootFolder::class); - $node = $root->getFirstNodeByIdInPath($task->getOutput()['spectrogram'], '/' . $root->getAppDataDirectoryName() . '/'); + $node = $this->rootFolder->getFirstNodeByIdInPath($task->getOutput()['spectrogram'], '/' . $this->rootFolder->getAppDataDirectoryName() . '/'); self::assertNotNull($node); self::assertInstanceOf(\OCP\Files\File::class, $node); self::assertEquals('World', $node->getContent()); - } public function testNonexistentTask() { @@ -731,6 +728,10 @@ class TaskProcessingTest extends \Test\TestCase { self::assertIsArray($task->getOutput()['images']); self::assertCount(3, $task->getOutput()['images']); self::assertTrue($this->providers[SuccessfulTextToImageProvider::class]->ran); + $node = $this->rootFolder->getFirstNodeByIdInPath($task->getOutput()['images'][0], '/' . $this->rootFolder->getAppDataDirectoryName() . '/'); + self::assertNotNull($node); + self::assertInstanceOf(\OCP\Files\File::class, $node); + self::assertEquals('test', $node->getContent()); } public function testShouldTransparentlyHandleFailingText2ImageProviders() { |