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

[HttpFoundation] use atomic writes in MockFileSessionStorage #39816

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
Jan 14, 2021
Merged
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
[HttpFoundation] use atomic writes in MockFileSessionStorage
  • Loading branch information
nicolas-grekas committed Jan 13, 2021
commit 5290e978bdb8cdd66290d1344d57f088227db31a
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ public function save()

try {
if ($data) {
file_put_contents($this->getFilePath(), serialize($data));
$path = $this->getFilePath();
$tmp = $path.bin2hex(random_bytes(6));
file_put_contents($tmp, serialize($data));
rename($tmp, $path);
} else {
$this->destroy();
}
Expand All @@ -123,8 +126,11 @@ public function save()
*/
private function destroy(): void
{
if (is_file($this->getFilePath())) {
set_error_handler(static function () {});
try {
unlink($this->getFilePath());
} finally {
restore_error_handler();
}
}

Expand All @@ -141,8 +147,14 @@ private function getFilePath(): string
*/
private function read(): void
{
$filePath = $this->getFilePath();
$this->data = is_readable($filePath) && is_file($filePath) ? unserialize(file_get_contents($filePath)) : [];
set_error_handler(static function () {});
try {
$data = file_get_contents($this->getFilePath());
} finally {
restore_error_handler();
}

$this->data = $data ? unserialize($data) : [];

$this->loadSession();
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.