Skip to content
Snippets Groups Projects
Commit af05b488 authored by Thijs Kinkhorst's avatar Thijs Kinkhorst Committed by Tim van Dijen
Browse files

Fix atomically writing to a file

For the trick to work, the file needs to be on the same filesystem.
The tempdir is likely not on the same filesystem so the rename will
not be instantaneous. This probably worked in the past when the
tempdir was expected to be a subdir of the SimpleSAMLphp installation.

Fix it by writing a file to the same directory as the target file,
which will always be on the same FS. Also do not just use a rand()
number but something more random as we do in other places in the code.
parent 0dbf3d7b
No related branches found
No related tags found
No related merge requests found
......@@ -209,7 +209,7 @@ class System
*/
public function writeFile(string $filename, string $data, int $mode = 0600): void
{
$tmpFile = $this->getTempDir() . DIRECTORY_SEPARATOR . rand();
$tmpFile = $filename . '.' . bin2hex(random_bytes(4));
$res = @file_put_contents($tmpFile, $data);
if ($res === false) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment