-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload.platform.functions.php
More file actions
66 lines (58 loc) · 2.04 KB
/
Copy pathload.platform.functions.php
File metadata and controls
66 lines (58 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php declare(strict_types=1);
// @package webkernel/platform/load.platform.functions.php
if (!function_exists('webkernel_enforce_fs')) {
/**
* Enforce ownership and permissions on critical filesystem paths.
*
* @param string $basePath Absolute project root.
* @param int $dirMode Octal mode for directories (default 0755).
* @param int $fileMode Octal mode for writable files (default 0644).
*/
function webkernel_enforce_fs(
string $basePath,
int $dirMode = 0755,
int $fileMode = 0644
): void {
static $targets = [
'storage',
'storage/framework',
'storage/framework/cache',
'storage/framework/sessions',
'storage/framework/views',
'storage/logs',
'bootstrap/cache',
'packages',
];
$uid = null;
$gid = null;
if (function_exists('posix_getpwuid') && function_exists('posix_geteuid')) {
$info = posix_getpwuid(posix_geteuid());
if ($info !== false) {
$uid = $info['uid'];
$gid = $info['gid'];
}
}
$base = rtrim($basePath, DIRECTORY_SEPARATOR);
foreach ($targets as $rel) {
$path = $base . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $rel);
if (!is_dir($path)) {
$prev = umask(0);
@mkdir($path, $dirMode, true);
umask($prev);
}
if (!is_dir($path)) {
continue; // creation silently failed — skip, do not abort boot
}
if ((fileperms($path) & 0777) !== $dirMode) {
@chmod($path, $dirMode);
}
if ($uid !== null && function_exists('chown')) {
$stat = @stat($path);
if ($stat !== false && $stat['uid'] !== $uid) {
@chown($path, $uid);
@chgrp($path, $gid);
}
}
}
}
}