Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
use exceptions for error signaling in writeStream
this remove the ambiguity when writing zero length files

Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Jul 31, 2020
commit 98ca765572568640f17f917a0877944d0b9f57cb
16 changes: 12 additions & 4 deletions lib/private/Files/Storage/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
use OC\Files\Storage\Wrapper\Wrapper;
use OCP\Files\EmptyFileNameException;
use OCP\Files\FileNameTooLongException;
use OCP\Files\GenericFileException;
use OCP\Files\InvalidCharacterInPathException;
use OCP\Files\InvalidDirectoryException;
use OCP\Files\InvalidPathException;
Expand Down Expand Up @@ -618,10 +619,14 @@ public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
}
} else {
$source = $sourceStorage->fopen($sourceInternalPath, 'r');
$result = false;
if ($source) {
$result = $this->writeStream($targetInternalPath, $source) > 0;
} else {
$result = false;
try {
$this->writeStream($targetInternalPath, $source);
$result = true;
} catch (\Exception $e) {
\OC::$server->getLogger()->logException($e, ['level' => ILogger::WARN, 'message' => 'Failed to copy stream to storage']);
}
}

if ($result and $preserveMtime) {
Expand Down Expand Up @@ -852,10 +857,13 @@ public function needsPartFile() {
public function writeStream(string $path, $stream, int $size = null): int {
$target = $this->fopen($path, 'w');
if (!$target) {
return 0;
throw new GenericFileException("Failed to open $path for writing");
}
try {
[$count, $result] = \OC_Helper::streamCopy($stream, $target);
if (!$result) {
throw new GenericFileException("Failed to copy stream");
}
} finally {
fclose($target);
fclose($stream);
Expand Down
8 changes: 7 additions & 1 deletion lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use OC\Files\Filesystem;
use OC\Files\Storage\Wrapper\Jail;
use OCP\Files\ForbiddenException;
use OCP\Files\GenericFileException;
use OCP\Files\Storage\IStorage;
use OCP\ILogger;

Expand Down Expand Up @@ -500,6 +501,11 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
}

public function writeStream(string $path, $stream, int $size = null): int {
return (int)file_put_contents($this->getSourcePath($path), $stream);
$result = file_put_contents($this->getSourcePath($path), $stream);
if ($result === false) {
throw new GenericFileException("Failed write steam to $path");
} else {
return $result;
}
}
}
1 change: 0 additions & 1 deletion tests/lib/Files/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Common;
use OC\Files\Storage\Temporary;
use OC\Files\Stream\Quota;
use OC\Files\View;
use OCP\Files\Config\IMountProvider;
use OCP\Files\FileInfo;
Expand Down