Merge pull request #11495 from annando/warning

Avoid warning "fileperms(): stat failed for ..."
This commit is contained in:
Hypolite Petovan 2022-05-11 13:46:06 -04:00 committed by GitHub
commit 610b3fc39e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -124,18 +124,15 @@ class Avatar
foreach (explode('/', dirname($filename)) as $part) { foreach (explode('/', dirname($filename)) as $part) {
$dirpath .= $part . '/'; $dirpath .= $part . '/';
$old_perm = fileperms($dirpath) & 0777;
$old_group = filegroup($dirpath);
if (!file_exists($dirpath)) { if (!file_exists($dirpath)) {
if (!mkdir($dirpath, $dir_perm)) { if (!mkdir($dirpath, $dir_perm)) {
Logger::warning('Directory could not be created', ['directory' => $dirpath]); Logger::warning('Directory could not be created', ['directory' => $dirpath]);
} }
} elseif (($old_perm != $dir_perm) && !chmod($dirpath, $dir_perm)) { } elseif ((($old_perm = fileperms($dirpath) & 0777) != $dir_perm) && !chmod($dirpath, $dir_perm)) {
Logger::notice('Directory permissions could not be changed', ['directory' => $dirpath, 'old' => $old_perm, 'new' => $dir_perm]); Logger::notice('Directory permissions could not be changed', ['directory' => $dirpath, 'old' => $old_perm, 'new' => $dir_perm]);
} }
if (($old_group != $group) && !chgrp($dirpath, $group)) { if ((($old_group = filegroup($dirpath)) != $group) && !chgrp($dirpath, $group)) {
Logger::notice('Directory group could not be changed', ['directory' => $dirpath, 'old' => $old_group, 'new' => $group]); Logger::notice('Directory group could not be changed', ['directory' => $dirpath, 'old' => $old_group, 'new' => $group]);
} }
} }