2015-11-26 11:47:53 -05:00
|
|
|
<?php
|
2024-05-23 03:26:56 -04:00
|
|
|
|
2015-11-26 11:47:53 -05:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-11-26 11:47:53 -05:00
|
|
|
*/
|
|
|
|
|
namespace OC\Files\Config;
|
|
|
|
|
|
|
|
|
|
use OC\Files\Filesystem;
|
|
|
|
|
use OCP\Files\Config\ICachedMountInfo;
|
|
|
|
|
use OCP\Files\Node;
|
|
|
|
|
use OCP\IUser;
|
|
|
|
|
|
|
|
|
|
class CachedMountInfo implements ICachedMountInfo {
|
2022-02-10 08:15:07 -05:00
|
|
|
protected IUser $user;
|
|
|
|
|
protected int $storageId;
|
|
|
|
|
protected int $rootId;
|
|
|
|
|
protected string $mountPoint;
|
|
|
|
|
protected ?int $mountId;
|
|
|
|
|
protected string $rootInternalPath;
|
|
|
|
|
protected string $mountProvider;
|
2023-10-23 07:27:13 -04:00
|
|
|
protected string $key;
|
2022-02-02 10:12:57 -05:00
|
|
|
|
2015-11-26 11:47:53 -05:00
|
|
|
/**
|
|
|
|
|
* CachedMountInfo constructor.
|
|
|
|
|
*
|
|
|
|
|
* @param IUser $user
|
|
|
|
|
* @param int $storageId
|
|
|
|
|
* @param int $rootId
|
|
|
|
|
* @param string $mountPoint
|
2016-07-13 10:29:51 -04:00
|
|
|
* @param int|null $mountId
|
2016-09-18 12:36:53 -04:00
|
|
|
* @param string $rootInternalPath
|
2015-11-26 11:47:53 -05:00
|
|
|
*/
|
2022-02-02 10:12:57 -05:00
|
|
|
public function __construct(
|
|
|
|
|
IUser $user,
|
|
|
|
|
int $storageId,
|
|
|
|
|
int $rootId,
|
|
|
|
|
string $mountPoint,
|
|
|
|
|
string $mountProvider,
|
2024-03-28 11:13:19 -04:00
|
|
|
?int $mountId = null,
|
2022-02-02 10:12:57 -05:00
|
|
|
string $rootInternalPath = '',
|
|
|
|
|
) {
|
2015-11-26 11:47:53 -05:00
|
|
|
$this->user = $user;
|
|
|
|
|
$this->storageId = $storageId;
|
|
|
|
|
$this->rootId = $rootId;
|
|
|
|
|
$this->mountPoint = $mountPoint;
|
2016-07-13 10:29:51 -04:00
|
|
|
$this->mountId = $mountId;
|
2016-09-18 12:36:53 -04:00
|
|
|
$this->rootInternalPath = $rootInternalPath;
|
2022-02-02 10:12:57 -05:00
|
|
|
if (strlen($mountProvider) > 128) {
|
|
|
|
|
throw new \Exception("Mount provider $mountProvider name exceeds the limit of 128 characters");
|
|
|
|
|
}
|
|
|
|
|
$this->mountProvider = $mountProvider;
|
2023-10-23 07:27:13 -04:00
|
|
|
$this->key = $rootId . '::' . $mountPoint;
|
2015-11-26 11:47:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return IUser
|
|
|
|
|
*/
|
2022-02-10 08:15:07 -05:00
|
|
|
public function getUser(): IUser {
|
2015-11-26 11:47:53 -05:00
|
|
|
return $this->user;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return int the numeric storage id of the mount
|
|
|
|
|
*/
|
2022-02-10 08:15:07 -05:00
|
|
|
public function getStorageId(): int {
|
2015-11-26 11:47:53 -05:00
|
|
|
return $this->storageId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return int the fileid of the root of the mount
|
|
|
|
|
*/
|
2022-02-10 08:15:07 -05:00
|
|
|
public function getRootId(): int {
|
2015-11-26 11:47:53 -05:00
|
|
|
return $this->rootId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-02-10 08:15:07 -05:00
|
|
|
* @return Node|null the root node of the mount
|
2015-11-26 11:47:53 -05:00
|
|
|
*/
|
2022-02-10 08:15:07 -05:00
|
|
|
public function getMountPointNode(): ?Node {
|
2015-11-26 11:47:53 -05:00
|
|
|
// TODO injection etc
|
2016-04-15 08:03:48 -04:00
|
|
|
Filesystem::initMountPoints($this->getUser()->getUID());
|
|
|
|
|
$userNode = \OC::$server->getUserFolder($this->getUser()->getUID());
|
2024-02-09 03:54:52 -05:00
|
|
|
return $userNode->getParent()->getFirstNodeById($this->getRootId());
|
2015-11-26 11:47:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string the mount point of the mount for the user
|
|
|
|
|
*/
|
2022-02-10 08:15:07 -05:00
|
|
|
public function getMountPoint(): string {
|
2015-11-26 11:47:53 -05:00
|
|
|
return $this->mountPoint;
|
|
|
|
|
}
|
2016-07-13 10:29:51 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the id of the configured mount
|
|
|
|
|
*
|
|
|
|
|
* @return int|null mount id or null if not applicable
|
|
|
|
|
* @since 9.1.0
|
|
|
|
|
*/
|
2022-02-10 08:15:07 -05:00
|
|
|
public function getMountId(): ?int {
|
2016-07-13 10:29:51 -04:00
|
|
|
return $this->mountId;
|
|
|
|
|
}
|
2016-09-18 12:36:53 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the internal path (within the storage) of the root of the mount
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2022-02-10 08:15:07 -05:00
|
|
|
public function getRootInternalPath(): string {
|
2016-09-18 12:36:53 -04:00
|
|
|
return $this->rootInternalPath;
|
|
|
|
|
}
|
2022-02-02 10:12:57 -05:00
|
|
|
|
|
|
|
|
public function getMountProvider(): string {
|
|
|
|
|
return $this->mountProvider;
|
|
|
|
|
}
|
2023-10-23 07:27:13 -04:00
|
|
|
|
|
|
|
|
public function getKey(): string {
|
|
|
|
|
return $this->key;
|
|
|
|
|
}
|
2015-11-26 11:47:53 -05:00
|
|
|
}
|