Show permissions in properties

This commit is contained in:
Mikei386
2026-06-23 09:06:23 +02:00
parent dd011bbaa4
commit 74ba8d0984
6 changed files with 48 additions and 4 deletions
@@ -13,12 +13,20 @@ foreach (scandir($resolved['path']) ?: [] as $name) {
}
$full = $resolved['path'] . '/' . $name;
$type = is_link($full) ? 'symlink' : (is_dir($full) ? 'directory' : (is_file($full) ? 'file' : 'other'));
$ownerId = fileowner($full);
$groupId = filegroup($full);
$perms = fileperms($full);
$entries[] = [
'name' => $name,
'path' => $full,
'type' => $type,
'size' => is_file($full) ? filesize($full) : 0,
'modifiedAt' => date(DATE_ATOM, filemtime($full) ?: time()),
'owner' => unav_owner_name($ownerId),
'ownerId' => $ownerId,
'group' => unav_group_name($groupId),
'groupId' => $groupId,
'permissions' => $perms === false ? null : substr(sprintf('%o', $perms), -4),
];
}
@@ -32,3 +40,29 @@ unav_json([
'path' => $resolved['path'],
'entries' => $entries,
]);
function unav_owner_name($uid): ?string {
if ($uid === false) {
return null;
}
if (function_exists('posix_getpwuid')) {
$info = posix_getpwuid($uid);
if (is_array($info) && isset($info['name'])) {
return $info['name'];
}
}
return (string)$uid;
}
function unav_group_name($gid): ?string {
if ($gid === false) {
return null;
}
if (function_exists('posix_getgrgid')) {
$info = posix_getgrgid($gid);
if (is_array($info) && isset($info['name'])) {
return $info['name'];
}
}
return (string)$gid;
}