Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Filesystem] Add third argument $lockFile to Filesystem::appendToFile() #43796

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

Merged
merged 1 commit into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
[Filesystem] Add third argument $lockFile to `Filesystem::appendToF…
…ile()`
  • Loading branch information
fwolfsjaeger authored and nicolas-grekas committed Oct 28, 2021
commit 1519828e44cb0957d452ee7e97bd8e3a62fa29f1
1 change: 1 addition & 0 deletions 1 src/Symfony/Component/Filesystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
---

* Add `Path` class
* Add `$lock` argument to `Filesystem::appendToFile()`

5.0.0
-----
Expand Down
7 changes: 5 additions & 2 deletions 7 src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,11 @@ public function dumpFile(string $filename, $content)
* Appends content to an existing file.
*
* @param string|resource $content The content to append
* @param bool $lock Whether the file should be locked when writing to it
*
* @throws IOException If the file is not writable
*/
public function appendToFile(string $filename, $content)
public function appendToFile(string $filename, $content/*, bool $lock = false*/)
{
if (\is_array($content)) {
throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be string or resource, array given.', __METHOD__));
Expand All @@ -707,7 +708,9 @@ public function appendToFile(string $filename, $content)
$this->mkdir($dir);
}

if (false === self::box('file_put_contents', $filename, $content, \FILE_APPEND)) {
$lock = \func_num_args() > 2 && func_get_arg(2);

if (false === self::box('file_put_contents', $filename, $content, \FILE_APPEND | ($lock ? \LOCK_EX : 0))) {
throw new IOException(sprintf('Failed to write file "%s": ', $filename).self::$lastError, 0, null, $filename);
}
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.