(string $folder, string $user, array $perms, int $maxScan = 20000, ?int $maxDepth = null)
| 463 | } |
| 464 | |
| 465 | private static function countVisibleDeepRemote(string $folder, string $user, array $perms, int $maxScan = 20000, ?int $maxDepth = null): array |
| 466 | { |
| 467 | $storage = self::storage(); |
| 468 | |
| 469 | $canViewFolder = ACL::isAdmin($perms) |
| 470 | || ACL::canRead($user, $perms, $folder) |
| 471 | || ACL::canReadOwn($user, $perms, $folder); |
| 472 | if (!$canViewFolder) { |
| 473 | return ['folders' => 0, 'files' => 0, 'bytes' => 0, 'truncated' => false]; |
| 474 | } |
| 475 | |
| 476 | if ($maxDepth !== null) { |
| 477 | $maxDepth = (int)$maxDepth; |
| 478 | if ($maxDepth <= 0) { |
| 479 | $maxDepth = null; |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | $base = rtrim(self::uploadRoot(), "/\\"); |
| 484 | if ($base === '') { |
| 485 | return ['folders' => 0, 'files' => 0, 'bytes' => 0, 'truncated' => false]; |
| 486 | } |
| 487 | |
| 488 | $dirPath = ($folder === 'root') |
| 489 | ? $base |
| 490 | : $base . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $folder); |
| 491 | $startRel = ($folder === 'root') ? '' : $folder; |
| 492 | |
| 493 | $SKIP = FS::SKIP(); |
| 494 | |
| 495 | $folderCount = 0; |
| 496 | $fileCount = 0; |
| 497 | $totalBytes = 0; |
| 498 | $scanned = 0; |
| 499 | $truncated = false; |
| 500 | |
| 501 | $stack = [[$dirPath, $startRel, 0]]; |
| 502 | while ($stack) { |
| 503 | [$curAbs, $curRel, $depth] = array_pop($stack); |
| 504 | $relForAcl = ($curRel === '' ? 'root' : $curRel); |
| 505 | $hasFullRead = ACL::isAdmin($perms) || ACL::canRead($user, $perms, $relForAcl); |
| 506 | |
| 507 | $entries = $storage->list($curAbs); |
| 508 | if (!$entries) { |
| 509 | continue; |
| 510 | } |
| 511 | |
| 512 | foreach ($entries as $name) { |
| 513 | if (++$scanned > $maxScan) { |
| 514 | $truncated = true; |
| 515 | break 2; |
| 516 | } |
| 517 | |
| 518 | if ($name === '.' || $name === '..' || $name === '') { |
| 519 | continue; |
| 520 | } |
| 521 | if ($name[0] === '.') { |
| 522 | continue; |
no test coverage detected