Merge pull request #22739 from nextcloud/bugfix/16989

Don't fail if copying a file of 0 byte size
This commit is contained in:
Morris Jobke 2020-09-10 15:16:19 +02:00 committed by GitHub
commit 0aa442220b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -52,6 +52,7 @@ use OCP\Encryption\Exceptions\GenericEncryptionException;
use OCP\Files\EntityTooLargeException;
use OCP\Files\FileInfo;
use OCP\Files\ForbiddenException;
use OCP\Files\GenericFileException;
use OCP\Files\InvalidContentException;
use OCP\Files\InvalidPathException;
use OCP\Files\LockNotAcquiredException;
@ -200,8 +201,14 @@ class File extends Node implements IFile {
$isEOF = feof($stream);
});
$count = $partStorage->writeStream($internalPartPath, $wrappedData);
$result = $count > 0;
$result = true;
$count = -1;
try {
$count = $partStorage->writeStream($internalPartPath, $wrappedData);
} catch (GenericFileException $e) {
$result = false;
}
if ($result === false) {
$result = $isEOF;

View File

@ -26,6 +26,8 @@ declare(strict_types=1);
namespace OCP\Files\Storage;
use OCP\Files\GenericFileException;
/**
* Interface that adds the ability to write a stream directly to file
*
@ -39,6 +41,7 @@ interface IWriteStreamStorage extends IStorage {
* @param resource $stream
* @param int|null $size the size of the stream if known in advance
* @return int the number of bytes written
* @throws GenericFileException
* @since 15.0.0
*/
public function writeStream(string $path, $stream, int $size = null): int;