MCPcopy Create free account
hub / github.com/error311/FileRise / checkExisting

Method checkExisting

src/FileRise/Domain/UploadModel.php:1604–1678  ·  view source on GitHub ↗

* Check which files already exist in the target folder. * * @param string $folder Normalized folder (e.g., "root" or "team/reports"). * @param array $files Array of ['path' => 'sub/file.txt', 'size' => 123]. * @return array */

(string $folder, array $files)

Source from the content-addressed store, hash-verified

1602 * @return array
1603 */
1604 public static function checkExisting(string $folder, array $files): array
1605 {
1606 $storage = StorageRegistry::getAdapter();
1607 $folderSan = self::sanitizeFolder($folder);
1608 $existing = [];
1609 $seen = [];
1610
1611 foreach ($files as $entry) {
1612 if (!is_array($entry)) {
1613 continue;
1614 }
1615 $rawPath = isset($entry['path']) ? (string)$entry['path'] : '';
1616 if ($rawPath === '') {
1617 continue;
1618 }
1619 $path = str_replace('\\', '/', trim($rawPath));
1620 $path = ltrim($path, '/');
1621 if ($path === '') {
1622 continue;
1623 }
1624 if (isset($seen[$path])) {
1625 continue;
1626 }
1627 $seen[$path] = true;
1628
1629 [$subDir, $fileName] = self::parseRelativePath($path);
1630 if ($subDir === null || $fileName === '') {
1631 continue;
1632 }
1633
1634 $storagePath = self::buildStoragePath($folderSan, $subDir, $fileName);
1635 $exists = false;
1636 $existingSize = null;
1637
1638 if ($storage->isLocal()) {
1639 if (is_file($storagePath)) {
1640 $exists = true;
1641 $size = @filesize($storagePath);
1642 $existingSize = ($size === false) ? null : (int)$size;
1643 }
1644 } else {
1645 try {
1646 $stat = $storage->stat($storagePath);
1647 if ($stat && ($stat['type'] ?? '') === 'file') {
1648 $exists = true;
1649 $size = $stat['size'] ?? null;
1650 $existingSize = ($size === null) ? null : (int)$size;
1651 }
1652 } catch (\Throwable $e) {
1653 // Best-effort: treat as non-existing on stat errors.
1654 }
1655 }
1656
1657 if (!$exists) {
1658 continue;
1659 }
1660
1661 $reqSize = null;

Callers 1

checkExisting.phpFile · 0.45

Calls 6

sanitizeFolderMethod · 0.95
parseRelativePathMethod · 0.95
buildStoragePathMethod · 0.95
getAdapterMethod · 0.80
isLocalMethod · 0.45
statMethod · 0.45

Tested by

no test coverage detected