Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong object passed to the mount provider in VersionsBackend::getAllVersionedFiles #1725

Merged
merged 1 commit into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/Folder/FolderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OCP\Constants;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\IMimeTypeLoader;
use OCP\Files\IRootFolder;
use OCP\IDBConnection;
Expand Down Expand Up @@ -62,7 +63,7 @@ public function __construct(IDBConnection $connection, IGroupManager $groupManag
/**
* @return (array|bool|int|mixed)[][]
*
* @psalm-return array<int, array{id: int, mount_point: mixed, groups: array<empty, empty>|mixed, quota: mixed, size: int, acl: bool}>
* @psalm-return array<int, array{id: int, mount_point: mixed, groups: array<empty, empty>|array<array-key, int>, quota: mixed, size: int, acl: bool}>
* @throws Exception
*/
public function getAllFolders(): array {
Expand Down Expand Up @@ -116,7 +117,7 @@ private function joinQueryWithFileCache(IQueryBuilder $query, int $rootStorageId
/**
* @return (array|bool|int|mixed)[][]
*
* @psalm-return array<int, array{id: int, mount_point: mixed, groups: array<empty, empty>|mixed, quota: mixed, size: int|mixed, acl: bool, manage: mixed}>
* @psalm-return array<int, array{id: int, mount_point: mixed, groups: array<empty, empty>|array<array-key, int>, quota: mixed, size: int|mixed, acl: bool, manage: mixed}>
* @throws Exception
*/
public function getAllFoldersWithSize(int $rootStorageId): array {
Expand Down Expand Up @@ -354,7 +355,7 @@ public function searchUsers(int $id, string $search = '', int $limit = 10, int $
/**
* @param string $groupId
* @param int $rootStorageId
* @return array[]
* @return list<array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?ICacheEntry}>
* @throws Exception
*/
public function getFoldersForGroup(string $groupId, int $rootStorageId = 0): array {
Expand Down Expand Up @@ -406,7 +407,7 @@ public function getFoldersForGroup(string $groupId, int $rootStorageId = 0): arr
/**
* @param string[] $groupIds
* @param int $rootStorageId
* @return array[]
* @return list<array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?ICacheEntry}>
* @throws Exception
*/
public function getFoldersForGroups(array $groupIds, int $rootStorageId = 0): array {
Expand Down
21 changes: 15 additions & 6 deletions lib/Mount/MountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
use OCP\Files\Config\IMountProvider;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\Folder;
use OCP\Files\Node;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorage;
Expand Down Expand Up @@ -87,7 +89,10 @@ public function __construct(
$this->connection = $connection;
}

public function getFoldersForUser(IUser $user) {
/**
* @return list<array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?ICacheEntry}>
*/
public function getFoldersForUser(IUser $user): array {
return $this->folderManager->getFoldersForUser($user, $this->getRootFolder()->getStorage()->getCache()->getNumericStorageId());
}

Expand Down Expand Up @@ -131,7 +136,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
}, $folders)));
}

private function getCurrentUID() {
private function getCurrentUID(): ?string {
try {
// wopi requests are not logged in, instead we need to get the editor user from the access token
if (strpos($this->request->getRawPathInfo(), 'apps/richdocuments/wopi') && class_exists('OCA\Richdocuments\Db\WopiMapper')) {
Expand All @@ -149,7 +154,7 @@ private function getCurrentUID() {
return $user ? $user->getUID() : null;
}

public function getMount($id, $mountPoint, $permissions, $quota, $cacheEntry = null, IStorageFactory $loader = null, bool $acl = false, IUser $user = null): ?IMountPoint {
CarlSchwan marked this conversation as resolved.
Show resolved Hide resolved
public function getMount(int $id, string $mountPoint, int $permissions, int $quota, ?ICacheEntry $cacheEntry = null, IStorageFactory $loader = null, bool $acl = false, IUser $user = null): ?IMountPoint {
if (!$cacheEntry) {
// trigger folder creation
$folder = $this->getFolder($id);
Expand All @@ -161,7 +166,7 @@ public function getMount($id, $mountPoint, $permissions, $quota, $cacheEntry = n

$storage = $this->getRootFolder()->getStorage();

$rootPath = $this->getJailPath((int)$id);
$rootPath = $this->getJailPath($id);

// apply acl before jail
if ($acl && $user) {
Expand Down Expand Up @@ -214,7 +219,7 @@ private function getRootFolder(): Folder {
return $this->root;
}

public function getFolder($id, $create = true) {
public function getFolder(int $id, bool $create = true): ?Node {
try {
return $this->getRootFolder()->get((string)$id);
} catch (NotFoundException $e) {
Expand All @@ -226,7 +231,11 @@ public function getFolder($id, $create = true) {
}
}

private function findConflictsForUser(IUser $user, array $mountPoints) {
/**
* @param string[] $mountPoints
* @return string[] An array of paths.
*/
private function findConflictsForUser(IUser $user, array $mountPoints): array {
$userHome = $this->mountProviderCollection->getHomeMountForUser($user);

$pathHashes = array_map('md5', $mountPoints);
Expand Down
7 changes: 5 additions & 2 deletions lib/Versions/GroupVersionsExpireManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,18 @@ public function __construct(
$this->dispatcher = $dispatcher;
}

public function expireAll() {
public function expireAll(): void {
$folders = $this->folderManager->getAllFolders();
foreach ($folders as $folder) {
$this->emit(self::class, 'enterFolder', [$folder]);
$this->expireFolder($folder);
}
}

public function expireFolder($folder) {
/**
* @param array{id: int, mount_point: mixed, groups: array<empty, empty>|array<array-key, int>, quota: mixed, size: int, acl: bool} $folder
*/
public function expireFolder(array $folder): void {
$view = new View('/__groupfolders/versions/' . $folder['id']);
$files = $this->versionsBackend->getAllVersionedFiles($folder);
$dummyUser = new User('', null, $this->dispatcher);
Expand Down
5 changes: 3 additions & 2 deletions lib/Versions/VersionsBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorage;
use OCP\IUser;
use OCP\Constant;

class VersionsBackend implements IVersionBackend {
/** @var Folder */
Expand Down Expand Up @@ -151,12 +152,12 @@ public function getVersionFile(IUser $user, FileInfo $sourceFile, $revision): Fi
}

/**
* @param array $folder
* @param array{id: int, mount_point: mixed, groups: array<empty, empty>|mixed, quota: mixed, size: int, acl: bool} $folder
* @return (FileInfo|null)[] [$fileId => FileInfo|null]
*/
public function getAllVersionedFiles(array $folder) {
$versionsFolder = $this->getVersionsFolder($folder['id']);
$mount = $this->mountProvider->getMount($folder['id'], '/dummyuser/files/' . $folder['mount_point'], $folder['groups'], $folder['quota']);
CarlSchwan marked this conversation as resolved.
Show resolved Hide resolved
$mount = $this->mountProvider->getMount($folder['id'], '/dummyuser/files/' . $folder['mount_point'], Constant::PERMISSION_ALL, $folder['quota']);
try {
$contents = $versionsFolder->getDirectoryListing();
} catch (NotFoundException $e) {
Expand Down