Merge pull request #22778 from nextcloud/backport/22739/stable19

[stable19] Don't fail if copying a file of 0 byte size
This commit is contained in:
Roeland Jago Douma 2020-09-11 08:45:21 +02:00 committed by GitHub
commit d43eeab39d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

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

View File

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