Skip to content

Commit e396e03

Browse files
committed
Merge branch 'MAGETWO-48894-fwrite-truncation-on-resource' into MAGETWO-43351-cart-price-rule-form
2 parents a44c946 + 3774453 commit e396e03

File tree

1 file changed

+24
-6
lines changed
  • lib/internal/Magento/Framework/Filesystem/Driver

1 file changed

+24
-6
lines changed

lib/internal/Magento/Framework/Filesystem/Driver/File.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -701,18 +701,36 @@ public function fileClose($resource)
701701
*/
702702
public function fileWrite($resource, $data)
703703
{
704-
$result = @fwrite($resource, $data);
705-
if (false === $result) {
706-
throw new FileSystemException(
707-
new \Magento\Framework\Phrase(
704+
$lenData = strlen($data);
705+
for ($result = 0; $result < $lenData; $result += $fwrite) {
706+
$fwrite = @fwrite($resource, substr($data, $result));
707+
if (0 === $fwrite) {
708+
$this->fileSystemException('Unable to write');
709+
}
710+
if (false === $fwrite) {
711+
$this->fileSystemException(
708712
'Error occurred during execution of fileWrite %1',
709713
[$this->getWarningMessage()]
710-
)
711-
);
714+
);
715+
}
712716
}
717+
713718
return $result;
714719
}
715720

721+
/**
722+
* Throw a FileSystemException with a Phrase of message and optional arguments
723+
*
724+
* @param string $message
725+
* @param array $arguments
726+
* @return void
727+
* @throws FileSystemException
728+
*/
729+
private function fileSystemException($message, $arguments = [])
730+
{
731+
throw new FileSystemException(new \Magento\Framework\Phrase($message, $arguments));
732+
}
733+
716734
/**
717735
* Writes one CSV row to the file.
718736
*

0 commit comments

Comments
 (0)