-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Verify bytes written in Filesystem::dumpFile() #36952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -663,8 +663,8 @@ public function tempnam($dir, $prefix) | |
/** | ||
* Atomically dumps content into a file. | ||
* | ||
* @param string $filename The file to be written to | ||
* @param string $content The data to write into the file | ||
* @param string $filename The file to be written to | ||
* @param string|resource|array $content The data to write into the file | ||
* | ||
* @throws IOException if the file cannot be written to | ||
*/ | ||
|
@@ -684,8 +684,14 @@ public function dumpFile($filename, $content) | |
// when the filesystem supports chmod. | ||
$tmpFile = $this->tempnam($dir, basename($filename)); | ||
|
||
if (false === @file_put_contents($tmpFile, $content)) { | ||
throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename); | ||
if (\is_resource($content)) { | ||
$expectedSize = fstat($content)['size']; | ||
} else { | ||
$expectedSize = array_sum(array_map('strlen', (array) $content)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't want to add support for arrays - they worked "by chance" but that's not supported There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are not dealing with arrays in 3.4 it would break the current behavior – the one that is only explicitly deprecated in 4.0. That doesn’t seem the right thing to do. |
||
} | ||
|
||
if ($expectedSize !== ($actualSize = @file_put_contents($tmpFile, $content))) { | ||
throw new IOException(sprintf('Failed to write file "%s". Wrote %d of %d bytes.', $filename, $actualSize, $expectedSize), 0, null, $filename); | ||
} | ||
|
||
@chmod($tmpFile, file_exists($filename) ? fileperms($filename) : 0666 & ~umask()); | ||
|
Uh oh!
There was an error while loading. Please reload this page.