(StorageAdapterInterface $storage, string $realFolderPath, ?string $shareRootRealPath = null)
| 2519 | } |
| 2520 | |
| 2521 | private static function listSharedFolderEntries(StorageAdapterInterface $storage, string $realFolderPath, ?string $shareRootRealPath = null): array |
| 2522 | { |
| 2523 | $folders = []; |
| 2524 | $files = []; |
| 2525 | $all = $storage->list($realFolderPath); |
| 2526 | foreach ($all as $it) { |
| 2527 | if ($it === '.' || $it === '..') { |
| 2528 | continue; |
| 2529 | } |
| 2530 | if ($it === '' || $it[0] === '.') { |
| 2531 | continue; |
| 2532 | } |
| 2533 | |
| 2534 | $fullPath = $realFolderPath . DIRECTORY_SEPARATOR . $it; |
| 2535 | if ($storage->isLocal() && $shareRootRealPath !== null) { |
| 2536 | $real = realpath($fullPath); |
| 2537 | if ($real === false || !self::isPathInsideOrSame($shareRootRealPath, $real)) { |
| 2538 | continue; |
| 2539 | } |
| 2540 | } |
| 2541 | $stat = $storage->stat($fullPath); |
| 2542 | if ($stat === null) { |
| 2543 | continue; |
| 2544 | } |
| 2545 | $type = $stat['type'] ?? ''; |
| 2546 | if ($type === 'dir') { |
| 2547 | if (!preg_match(REGEX_FOLDER_NAME, $it)) { |
| 2548 | continue; |
| 2549 | } |
| 2550 | $folders[] = [ |
| 2551 | 'type' => 'folder', |
| 2552 | 'name' => $it, |
| 2553 | 'size' => null, |
| 2554 | 'modified' => self::extractStatMtime($stat), |
| 2555 | ]; |
| 2556 | continue; |
| 2557 | } |
| 2558 | if ($type === 'file') { |
| 2559 | if (!preg_match(REGEX_FILE_NAME, $it)) { |
| 2560 | continue; |
| 2561 | } |
| 2562 | $files[] = [ |
| 2563 | 'type' => 'file', |
| 2564 | 'name' => $it, |
| 2565 | 'size' => array_key_exists('size', $stat) ? (int)$stat['size'] : null, |
| 2566 | 'modified' => self::extractStatMtime($stat), |
| 2567 | ]; |
| 2568 | } |
| 2569 | } |
| 2570 | |
| 2571 | $sortByName = function (array $a, array $b): int { |
| 2572 | return strnatcasecmp($a['name'] ?? '', $b['name'] ?? ''); |
| 2573 | }; |
| 2574 | usort($folders, $sortByName); |
| 2575 | usort($files, $sortByName); |
| 2576 | |
| 2577 | return array_merge($folders, $files); |
| 2578 | } |
no test coverage detected