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;
}
} 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) {
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);
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;
}
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;
+ }
}
}
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;