8000 [Filesystem] Add third argument `$lockFile` to `Filesystem::appendToF… · symfony/symfony@1519828 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1519828

Browse files
fwolfsjaegernicolas-grekas
authored andcommitted
[Filesystem] Add third argument $lockFile to Filesystem::appendToFile()
1 parent ee6bbb2 commit 1519828

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/Symfony/Component/Filesystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add `Path` class
8+
* Add `$lock` argument to `Filesystem::appendToFile()`
89

910
5.0.0
1011
-----

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,10 +692,11 @@ public function dumpFile(string $filename, $content)
692692
* Appends content to an existing file.
693693
*
694694
* @param string|resource $content The content to append
695+
* @param bool $lock Whether the file should be locked when writing to it
695696
*
696697
* @throws IOException If the file is not writable
697698
*/
698-
public function appendToFile(string $filename, $content)
699+
public function appendToFile(string $filename, $content/*, bool $lock = false*/)
699700
{
700701
if (\is_array($content)) {
701702
throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be string or resource, array given.', __METHOD__));
@@ -707,7 +708,9 @@ public function appendToFile(string $filename, $content)
707708
$this->mkdir($dir);
708709
}
709710

710-
if (false === self::box('file_put_contents', $filename, $content, \FILE_APPEND)) {
711+
$lock = \func_num_args() > 2 && func_get_arg(2);
712+
713+
if (false === self::box('file_put_contents', $filename, $content, \FILE_APPEND | ($lock ? \LOCK_EX : 0))) {
711714
throw new IOException(sprintf('Failed to write file "%s": ', $filename).self::$lastError, 0, null, $filename);
712715
}
713716
}

0 commit comments

Comments
 (0)
0