Skip to content
Draft
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
67 changes: 57 additions & 10 deletions lib/private/Files/Config/CachedMountFileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,70 @@

namespace OC\Files\Config;

use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Config\ICachedMountFileInfo;
use OCP\Files\Config\ICachedMountInfo;
use OCP\Files\Node;
use OCP\IUser;

class CachedMountFileInfo extends CachedMountInfo implements ICachedMountFileInfo {
class CachedMountFileInfo implements ICachedMountFileInfo {
public function __construct(
IUser $user,
int $storageId,
int $rootId,
string $mountPoint,
?int $mountId,
string $mountProvider,
string $rootInternalPath,
private string $internalPath,
private readonly ICachedMountInfo $mountInfo,
private readonly string $internalPath,
) {
parent::__construct($user, $storageId, $rootId, $mountPoint, $mountProvider, $mountId, $rootInternalPath);
}

#[\Override]
public function getUser(): IUser {
return $this->mountInfo->getUser();
}

#[\Override]
public function getStorageId(): int {
return $this->mountInfo->getStorageId();
}

#[\Override]
public function getRootId(): int {
return $this->mountInfo->getRootId();
}

#[\Override]
public function getMountPointNode(): ?Node {
return $this->mountInfo->getMountPointNode();
}

#[\Override]
public function getMountPoint(): string {
return $this->mountInfo->getMountPoint();
}

#[\Override]
public function getMountId(): ?int {
return $this->mountInfo->getMountId();
}

#[\Override]
public function getRootInternalPath(): string {
return $this->mountInfo->getRootInternalPath();
}

#[\Override]
public function getMountProvider(): string {
return $this->mountInfo->getMountProvider();
}

#[\Override]
public function getKey(): string {
return $this->mountInfo->getKey();
}

#[\Override]
public function getRootCacheEntry(): ICacheEntry {
return $this->mountInfo->getRootCacheEntry();
}


#[\Override]
public function getInternalPath(): string {
if ($this->getRootInternalPath()) {
Expand Down
15 changes: 12 additions & 3 deletions lib/private/Files/Config/CachedMountInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace OC\Files\Config;

use OC\Files\Filesystem;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Config\ICachedMountInfo;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
Expand All @@ -25,7 +26,7 @@
protected string $mountPoint,
protected string $mountProvider,
protected ?int $mountId = null,
protected string $rootInternalPath = '',
protected ICacheEntry $rootCacheEntry,
) {
if (strlen($this->mountProvider) > 128) {
throw new \Exception("Mount provider $this->mountProvider name exceeds the limit of 128 characters");
Expand Down Expand Up @@ -60,7 +61,6 @@
#[\Override]
public function getMountPointNode(): ?Node {
// TODO injection etc
Filesystem::initMountPoints($this->getUser()->getUID());
$userFolder = Server::get(IRootFolder::class)->getUserFolder($this->getUser()->getUID());
return $userFolder->getParent()->getFirstNodeById($this->getRootId());
}
Expand Down Expand Up @@ -91,7 +91,7 @@
*/
#[\Override]
public function getRootInternalPath(): string {
return $this->rootInternalPath;
return $this->getRootCacheEntry()->getPath();
}

#[\Override]
Expand All @@ -103,4 +103,13 @@
public function getKey(): string {
return $this->key;
}

/**
* Get the cached file data for the root of the mount
*
* @return ICacheEntry
*/
public function getRootCacheEntry(): ICacheEntry {

Check failure on line 112 in lib/private/Files/Config/CachedMountInfo.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MissingOverrideAttribute

lib/private/Files/Config/CachedMountInfo.php:112:2: MissingOverrideAttribute: Method OC\Files\Config\CachedMountInfo::getrootcacheentry should have the "Override" attribute (see https://psalm.dev/358)
return $this->rootCacheEntry;
}
}
51 changes: 37 additions & 14 deletions lib/private/Files/Config/LazyStorageMountInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,54 @@

namespace OC\Files\Config;

use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Config\ICachedMountInfo;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Node;
use OCP\IUser;
use OCP\Server;

class LazyStorageMountInfo implements ICachedMountInfo {
private ?string $key = null;
private ?int $storageId = null;
private ?int $rootId = null;
private ?ICacheEntry $rootCacheEntry = null;

class LazyStorageMountInfo extends CachedMountInfo {
public function __construct(
IUser $user,
private IMountPoint $mount,
private readonly IUser $user,
private readonly IMountPoint $mount,
) {
parent::__construct($user, 0, 0, '', '');
$this->key = '';
}

/**
* @return int the numeric storage id of the mount

Check failure on line 32 in lib/private/Files/Config/LazyStorageMountInfo.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidNullableReturnType

lib/private/Files/Config/LazyStorageMountInfo.php:32:13: InvalidNullableReturnType: The declared return type 'int' for OC\Files\Config\LazyStorageMountInfo::getStorageId is not nullable, but 'int|null' contains null (see https://psalm.dev/144)
*/
#[\Override]
public function getStorageId(): int {
if (!$this->storageId) {
if ($this->storageId === null) {
$this->storageId = $this->mount->getNumericStorageId();
}
return parent::getStorageId();
return $this->storageId;

Check failure on line 39 in lib/private/Files/Config/LazyStorageMountInfo.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

NullableReturnStatement

lib/private/Files/Config/LazyStorageMountInfo.php:39:10: NullableReturnStatement: The declared return type 'int' for OC\Files\Config\LazyStorageMountInfo::getStorageId is not nullable, but the function returns 'int|null' (see https://psalm.dev/139)
}

/**
* @return int the fileid of the root of the mount
*/
#[\Override]
public function getRootId(): int {
if (!$this->rootId) {
if ($this->rootId === null) {
$this->rootId = $this->mount->getStorageRootId();
}
return parent::getRootId();
return $this->rootId;
}

/**
* @return string the mount point of the mount for the user
*/
#[\Override]
public function getMountPoint(): string {
if (!$this->mountPoint) {
$this->mountPoint = $this->mount->getMountPoint();
}
return parent::getMountPoint();
return $this->mount->getMountPoint();
}

#[\Override]
Expand All @@ -75,9 +80,27 @@

#[\Override]
public function getKey(): string {
if (!$this->key) {
if ($this->key === null) {
$this->key = $this->getRootId() . '::' . $this->getMountPoint();
}
return $this->key;
}

public function getUser(): IUser {

Check failure on line 89 in lib/private/Files/Config/LazyStorageMountInfo.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MissingOverrideAttribute

lib/private/Files/Config/LazyStorageMountInfo.php:89:2: MissingOverrideAttribute: Method OC\Files\Config\LazyStorageMountInfo::getuser should have the "Override" attribute (see https://psalm.dev/358)
return $this->user;
}

public function getMountPointNode(): ?Node {

Check failure on line 93 in lib/private/Files/Config/LazyStorageMountInfo.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MissingOverrideAttribute

lib/private/Files/Config/LazyStorageMountInfo.php:93:2: MissingOverrideAttribute: Method OC\Files\Config\LazyStorageMountInfo::getmountpointnode should have the "Override" attribute (see https://psalm.dev/358)
$userFolder = Server::get(IRootFolder::class)->getUserFolder($this->getUser()->getUID());
return $userFolder->getParent()->getFirstNodeById($this->getRootId());
}

public function getRootCacheEntry(): ICacheEntry {

Check failure on line 98 in lib/private/Files/Config/LazyStorageMountInfo.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MissingOverrideAttribute

lib/private/Files/Config/LazyStorageMountInfo.php:98:2: MissingOverrideAttribute: Method OC\Files\Config\LazyStorageMountInfo::getrootcacheentry should have the "Override" attribute (see https://psalm.dev/358)
if ($this->rootCacheEntry === null) {
$this->rootCacheEntry = $this->mount->getStorage()->getCache()->get();

Check failure on line 100 in lib/private/Files/Config/LazyStorageMountInfo.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

TooFewArguments

lib/private/Files/Config/LazyStorageMountInfo.php:100:68: TooFewArguments: Too few arguments for OCP\Files\Cache\ICache::get - expecting file to be passed (see https://psalm.dev/025)
}
return $this->rootCacheEntry;
}


}
Loading
Loading