|
5 | 5 | * SPDX-FileCopyrightText: 2016 ownCloud, Inc. |
6 | 6 | * SPDX-License-Identifier: AGPL-3.0-only |
7 | 7 | */ |
| 8 | + |
8 | 9 | namespace OC\Files\Config; |
9 | 10 |
|
10 | 11 | use OC\DB\Exceptions\DbalException; |
@@ -33,11 +34,13 @@ class UserMountCache implements IUserMountCache { |
33 | 34 |
|
34 | 35 | /** |
35 | 36 | * Cached mount info. |
| 37 | + * |
36 | 38 | * @var CappedMemoryCache<ICachedMountInfo[]> |
37 | 39 | **/ |
38 | 40 | private CappedMemoryCache $mountsForUsers; |
39 | 41 | /** |
40 | 42 | * fileid => internal path mapping for cached mount info. |
| 43 | + * |
41 | 44 | * @var CappedMemoryCache<string> |
42 | 45 | **/ |
43 | 46 | private CappedMemoryCache $internalPathCache; |
@@ -73,7 +76,9 @@ public function registerMounts(IUser $user, array $mounts, ?array $mountProvider |
73 | 76 |
|
74 | 77 | $cachedMounts = $this->getMountsForUser($user); |
75 | 78 | if (is_array($mountProviderClasses)) { |
76 | | - $cachedMounts = array_filter($cachedMounts, function (ICachedMountInfo $mountInfo) use ($mountProviderClasses, $newMounts) { |
| 79 | + $cachedMounts = array_filter($cachedMounts, function ( |
| 80 | + ICachedMountInfo $mountInfo, |
| 81 | + ) use ($mountProviderClasses, $newMounts) { |
77 | 82 | // for existing mounts that didn't have a mount provider set |
78 | 83 | // we still want the ones that map to new mounts |
79 | 84 | if ($mountInfo->getMountProvider() === '' && isset($newMounts[$mountInfo->getKey()])) { |
@@ -536,7 +541,13 @@ public function removeMount(string $mountPoint, ?IUser $user = null): void { |
536 | 541 | } |
537 | 542 | } |
538 | 543 |
|
539 | | - public function addMount(IUser $user, string $mountPoint, ICacheEntry $rootCacheEntry, string $mountProvider, ?int $mountId = null): void { |
| 544 | + public function addMount( |
| 545 | + IUser $user, |
| 546 | + string $mountPoint, |
| 547 | + ICacheEntry $rootCacheEntry, |
| 548 | + string $mountProvider, |
| 549 | + ?int $mountId = null, |
| 550 | + ): void { |
540 | 551 | $query = $this->connection->getQueryBuilder(); |
541 | 552 | $query->insert('mounts') |
542 | 553 | ->values([ |
@@ -567,4 +578,26 @@ public function flush(): void { |
567 | 578 | $this->internalPathCache = new CappedMemoryCache(); |
568 | 579 | $this->mountsForUsers = new CappedMemoryCache(); |
569 | 580 | } |
| 581 | + |
| 582 | + public function getMountAtPath(IUser $user, string $mountPoint): ?ICachedMountInfo { |
| 583 | + if (isset($this->mountsForUsers[$user->getUID()])) { |
| 584 | + foreach ($this->mountsForUsers[$user->getUID()] as $mount) { |
| 585 | + if ($mount->getMountPoint() === $mountPoint) { |
| 586 | + return $mount; |
| 587 | + } |
| 588 | + } |
| 589 | + return null; |
| 590 | + } |
| 591 | + |
| 592 | + $builder = $this->connection->getQueryBuilder(); |
| 593 | + $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class') |
| 594 | + ->from('mounts', 'm') |
| 595 | + ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
| 596 | + ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($user->getUID()))) |
| 597 | + ->andWhere($builder->expr()->eq('mount_point', $builder->createNamedParameter($mountPoint))) |
| 598 | + ->setMaxResults(1); |
| 599 | + |
| 600 | + $row = $query->executeQuery()->fetch(); |
| 601 | + return $row ? $this->dbRowToMountInfo($row) : null; |
| 602 | + } |
570 | 603 | } |
0 commit comments