Skip to content

Commit f41fe2e

Browse files
solracsfblizzz
authored andcommitted
fix(chunkedUploads): Ensure max parallel count is at least 1
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> Signed-off-by: Josh <josh.t.richards@gmail.com>
1 parent b96f954 commit f41fe2e

3 files changed

Lines changed: 52 additions & 2 deletions

File tree

apps/files/lib/Service/ChunkedUploadConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public static function setMaxChunkSize(int $maxChunkSize): void {
2525
}
2626

2727
public static function getMaxParallelCount(): int {
28-
return Server::get(IConfig::class)->getSystemValueInt(self::KEY_MAX_PARALLEL_COUNT, 5);
28+
return max(1, Server::get(IConfig::class)->getSystemValueInt(self::KEY_MAX_PARALLEL_COUNT, 5));
2929
}
3030
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
namespace OCA\Files\Tests\Service;
9+
10+
use OCA\Files\Service\ChunkedUploadConfig;
11+
use OCP\IConfig;
12+
use PHPUnit\Framework\Attributes\DataProvider;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use Test\TestCase;
15+
16+
class ChunkedUploadConfigTest extends TestCase {
17+
private IConfig&MockObject $config;
18+
19+
protected function setUp(): void {
20+
parent::setUp();
21+
22+
$this->config = $this->createMock(IConfig::class);
23+
$this->overwriteService(IConfig::class, $this->config);
24+
}
25+
26+
protected function tearDown(): void {
27+
$this->restoreAllServices();
28+
parent::tearDown();
29+
}
30+
31+
public static function dataGetMaxParallelCount(): array {
32+
return [
33+
'configured positive value' => [3, 3],
34+
'boundary minimum' => [1, 1],
35+
'zero becomes one' => [0, 1],
36+
'negative becomes one' => [-2, 1],
37+
'large value passes through' => [100, 100],
38+
];
39+
}
40+
41+
#[DataProvider('dataGetMaxParallelCount')]
42+
public function testGetMaxParallelCount(int $configuredValue, int $expectedValue): void {
43+
$this->config->expects($this->once())
44+
->method('getSystemValueInt')
45+
->with('files.chunked_upload.max_parallel_count', 5)
46+
->willReturn($configuredValue);
47+
48+
$this->assertSame($expectedValue, ChunkedUploadConfig::getMaxParallelCount());
49+
}
50+
}

config/config.sample.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2798,7 +2798,7 @@
27982798
/**
27992799
* Maximum number of chunks uploaded in parallel during chunked uploads. Higher
28002800
* counts increase throughput but consume more server resources, with diminishing
2801-
* returns.
2801+
* returns. Value must be a positive integer.
28022802
*
28032803
* Defaults to ``5``
28042804
*/

0 commit comments

Comments
 (0)