Skip to content

Commit

Permalink
[Filesystem] Fix dumpFile stat failed error hitting custom handler
Browse files Browse the repository at this point in the history
Since #54471, dumpFile will trigger a `fileperms(): stat failed`
error when writing to a filename that does not yet exist. This
was silenced from PHP's default handler with the `@` operator.

However, the error is still passed to any custom handler that the
application has registered, and can therefore cause exceptions or
spurious logging depending on the implementation of the handler.

The better solution, which is consistent with all other calls to
native functions in this class, would be to use `self::box` to
catch and ignore the potential error so that it never leaks
outside this class.
  • Loading branch information
acoulton committed May 10, 2024
1 parent ca1c224 commit f538cda
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ public function dumpFile(string $filename, $content)
throw new IOException(sprintf('Failed to write file "%s": ', $filename).self::$lastError, 0, null, $filename);
}

self::box('chmod', $tmpFile, @fileperms($filename) ?: 0666 & ~umask());
self::box('chmod', $tmpFile, self::box('fileperms', $filename) ?: 0666 & ~umask());

$this->rename($tmpFile, $filename, true);
} finally {
Expand Down

0 comments on commit f538cda

Please sign in to comment.