Skip to content
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
refactor: Remove OC_Helper::streamCopy
Replace by Files::streamCopy, also deprecated but since less long

Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
  • Loading branch information
CarlSchwan committed Sep 28, 2025
commit 8e5eef24d2ef231f26354f1807de904947d50a5c
12 changes: 0 additions & 12 deletions lib/private/legacy/OC_Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,6 @@ public static function canExecute($name, $path = false) {
return false;
}

/**
* copy the contents of one stream to another
*
* @param resource $source
* @param resource $target
* @return array the number of bytes copied and result
* @deprecated 5.0.0 - Use \OCP\Files::streamCopy
*/
public static function streamCopy($source, $target) {
return \OCP\Files::streamCopy($source, $target, true);
}

/**
* Adds a suffix to the name in case the file exists
*
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Files/Storage/Wrapper/QuotaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function testStreamCopyWithEnoughSpace(): void {
$instance = $this->getLimitedStorage(16);
$inputStream = fopen('data://text/plain,foobarqwerty', 'r');
$outputStream = $instance->fopen('files/foo', 'w+');
[$count, $result] = \OC_Helper::streamCopy($inputStream, $outputStream);
[$count, $result] = Files::streamCopy($inputStream, $outputStream, true);
$this->assertEquals(12, $count);
$this->assertTrue($result);
fclose($inputStream);
Expand All @@ -126,7 +126,7 @@ public function testStreamCopyNotEnoughSpace(): void {
$instance = $this->getLimitedStorage(9);
$inputStream = fopen('data://text/plain,foobarqwerty', 'r');
$outputStream = $instance->fopen('files/foo', 'w+');
[$count, $result] = \OC_Helper::streamCopy($inputStream, $outputStream);
[$count, $result] = Files::streamCopy($inputStream, $outputStream, true);
$this->assertEquals(9, $count);
$this->assertFalse($result);
fclose($inputStream);
Expand Down
32 changes: 32 additions & 0 deletions tests/lib/FilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,36 @@ public function testRecursiveFolderDeletion(): void {
Files::rmdirr($baseDir);
$this->assertFalse(file_exists($baseDir));
}

#[\PHPUnit\Framework\Attributes\DataProvider('streamCopyDataProvider')]
public function testStreamCopy($expectedCount, $expectedResult, $source, $target): void {
if (is_string($source)) {
$source = fopen($source, 'r');
}
if (is_string($target)) {
$target = fopen($target, 'w');
}

[$count, $result] = Files::streamCopy($source, $target, true);

if (is_resource($source)) {
fclose($source);
}
if (is_resource($target)) {
fclose($target);
}

$this->assertSame($expectedCount, $count);
$this->assertSame($expectedResult, $result);
}


public static function streamCopyDataProvider(): array {
return [
[0, false, false, false],
[0, false, \OC::$SERVERROOT . '/tests/data/lorem.txt', false],
[filesize(\OC::$SERVERROOT . '/tests/data/lorem.txt'), true, \OC::$SERVERROOT . '/tests/data/lorem.txt', \OC::$SERVERROOT . '/tests/data/lorem-copy.txt'],
[3670, true, \OC::$SERVERROOT . '/tests/data/testimage.png', \OC::$SERVERROOT . '/tests/data/testimage-copy.png'],
];
}
}
44 changes: 0 additions & 44 deletions tests/lib/LegacyHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@
use OC_Helper;

class LegacyHelperTest extends \Test\TestCase {
/** @var string */
private $originalWebRoot;

protected function setUp(): void {
$this->originalWebRoot = \OC::$WEBROOT;
}

protected function tearDown(): void {
// Reset webRoot
\OC::$WEBROOT = $this->originalWebRoot;
}

public function testBuildNotExistingFileNameForView(): void {
$viewMock = $this->createMock(View::class);
$this->assertEquals('/filename', OC_Helper::buildNotExistingFileNameForView('/', 'filename', $viewMock));
Expand Down Expand Up @@ -115,36 +103,4 @@ public function testBuildNotExistingFileNameForView(): void {
]);
$this->assertEquals('dir/filename(1) (2) (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (2) (3).ext', $viewMock));
}

#[\PHPUnit\Framework\Attributes\DataProvider('streamCopyDataProvider')]
public function testStreamCopy($expectedCount, $expectedResult, $source, $target): void {
if (is_string($source)) {
$source = fopen($source, 'r');
}
if (is_string($target)) {
$target = fopen($target, 'w');
}

[$count, $result] = \OC_Helper::streamCopy($source, $target);

if (is_resource($source)) {
fclose($source);
}
if (is_resource($target)) {
fclose($target);
}

$this->assertSame($expectedCount, $count);
$this->assertSame($expectedResult, $result);
}


public static function streamCopyDataProvider(): array {
return [
[0, false, false, false],
[0, false, \OC::$SERVERROOT . '/tests/data/lorem.txt', false],
[filesize(\OC::$SERVERROOT . '/tests/data/lorem.txt'), true, \OC::$SERVERROOT . '/tests/data/lorem.txt', \OC::$SERVERROOT . '/tests/data/lorem-copy.txt'],
[3670, true, \OC::$SERVERROOT . '/tests/data/testimage.png', \OC::$SERVERROOT . '/tests/data/testimage-copy.png'],
];
}
}
Loading