fix: Silence PHP warnings from fopen and mkdir

We are testing the result and logging our own error anyway.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
This commit is contained in:
Côme Chilliet 2026-06-10 13:55:05 +02:00
parent 6515fa638a
commit b2a69d0095
No known key found for this signature in database
GPG key ID: A3E2F658B28C760A
2 changed files with 5 additions and 8 deletions

View file

@ -50,13 +50,14 @@ class TempManager implements ITempManager {
$path = $this->generateTemporaryPath($postFix);
$old_umask = umask(0077);
$fp = fopen($path, 'x');
$fp = @fopen($path, 'x');
umask($old_umask);
if ($fp === false) {
$this->log->warning(
'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions',
[
'dir' => $this->tmpBaseDir,
'error' => error_get_last(),
]
);
return false;
@ -71,11 +72,12 @@ class TempManager implements ITempManager {
public function getTemporaryFolder($postFix = ''): string|false {
$path = $this->generateTemporaryPath($postFix) . '/';
if (mkdir($path, 0700) === false) {
if (@mkdir($path, 0700) === false) {
$this->log->warning(
'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions',
[
'dir' => $this->tmpBaseDir,
'error' => error_get_last(),
]
);
return false;

View file

@ -36,12 +36,7 @@ class TempManagerTest extends \Test\TestCase {
parent::tearDown();
}
/**
* @param ?LoggerInterface $logger
* @param ?IConfig $config
* @return TempManager
*/
protected function getManager($logger = null, $config = null) {
protected function getManager(?LoggerInterface $logger = null, ?IConfig $config = null): TempManager {
if (!$logger) {
$logger = $this->createMock(LoggerInterface::class);
}