From: Michael Date: Mon, 9 May 2022 17:36:46 +0000 (+0000) Subject: Inherit avatar cache file permissions X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=916aa1c9a9d5c513bfac5c2107246ef936ab5a5e;p=friendica.git Inherit avatar cache file permissions --- diff --git a/src/Contact/Avatar.php b/src/Contact/Avatar.php index 13a99f9106..8aa72bf9ba 100644 --- a/src/Contact/Avatar.php +++ b/src/Contact/Avatar.php @@ -109,18 +109,32 @@ class Avatar $filepath = DI::basePath() . $path; - $dirpath = dirname($filepath); + $dirpath = DI::basePath() . '/avatar/'; DI::profiler()->startRecording('file'); - if (!file_exists($dirpath)) { - mkdir($dirpath, 0775, true); - } else { - chmod($dirpath, 0775); + // Fetch the permission and group ownership of the "avatar" path and apply to all files + $dir_perm = fileperms($dirpath) & 0777; + $file_perm = fileperms($dirpath) & 0666; + $group = filegroup($dirpath); + + // Check directory permissions of all parts of the path + foreach (explode('/', dirname($filename)) as $part) { + $dirpath .= $part . '/'; + if (!file_exists($dirpath)) { + mkdir($dirpath, $dir_perm); + } elseif (fileperms($dirpath) & 0777 != $dir_perm) { + chmod($dirpath, $dir_perm); + } + + if (filegroup($dirpath) != $group) { + chgrp($dirpath, $group); + } } file_put_contents($filepath, $image->asString()); - chmod($filepath, 0664); + chmod($filepath, $file_perm); + chgrp($filepath, $group); DI::profiler()->stopRecording();