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 {
|
2023-10-23 07:27:13 -04:00
|
|
|
protected string $key;
|
2022-02-02 10:12:57 -05:00
|
|
|
|
|
|
|
|
public function __construct(
|
2026-01-28 19:45:48 -05:00
|
|
|
protected IUser $user,
|
|
|
|
|
protected int $storageId,
|
|
|
|
|
protected int $rootId,
|
|
|
|
|
protected string $mountPoint,
|
|
|
|
|
protected string $mountProvider,
|
|
|
|
|
protected ?int $mountId = null,
|
|
|
|
|
protected string $rootInternalPath = '',
|
2022-02-02 10:12:57 -05:00
|
|
|
) {
|
2026-01-28 19:45:48 -05:00
|
|
|
if (strlen($this->mountProvider) > 128) {
|
|
|
|
|
throw new \Exception("Mount provider $this->mountProvider name exceeds the limit of 128 characters");
|
2022-02-02 10:12:57 -05:00
|
|
|
}
|
2026-01-28 19:45:48 -05:00
|
|
|
$this->key = $this->rootId . '::' . $this->mountPoint;
|
2015-11-26 11:47:53 -05:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|