2013-09-01 21:47:48 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 18:07:57 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Bernhard Posselt <dev@bernhard-posselt.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2016-07-21 18:07:57 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-07-21 18:07:57 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Stefan Weil <sw@weilnetz.de>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2015-03-26 13:44:34 +03:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-03-26 13:44:34 +03:00
|
|
|
*
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2013-09-01 21:47:48 +04:00
|
|
|
namespace OC\Files\Node;
|
|
|
|
|
2016-08-25 16:49:36 +03:00
|
|
|
use OC\Cache\CappedMemoryCache;
|
2013-09-01 21:47:48 +04:00
|
|
|
use OC\Files\Mount\Manager;
|
2014-11-24 17:54:42 +03:00
|
|
|
use OC\Files\Mount\MountPoint;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OC\Hooks\PublicEmitter;
|
2020-04-03 13:17:47 +03:00
|
|
|
use OC\User\NoUserException;
|
2016-09-18 19:36:53 +03:00
|
|
|
use OCP\Files\Config\IUserMountCache;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\Files\IRootFolder;
|
2013-09-10 21:44:23 +04:00
|
|
|
use OCP\Files\NotFoundException;
|
|
|
|
use OCP\Files\NotPermittedException;
|
2016-11-03 01:16:51 +03:00
|
|
|
use OCP\ILogger;
|
|
|
|
use OCP\IUserManager;
|
2014-12-20 17:59:31 +03:00
|
|
|
|
2013-09-01 21:47:48 +04:00
|
|
|
/**
|
|
|
|
* Class Root
|
|
|
|
*
|
|
|
|
* Hooks available in scope \OC\Files
|
2013-09-10 21:44:23 +04:00
|
|
|
* - preWrite(\OCP\Files\Node $node)
|
|
|
|
* - postWrite(\OCP\Files\Node $node)
|
|
|
|
* - preCreate(\OCP\Files\Node $node)
|
|
|
|
* - postCreate(\OCP\Files\Node $node)
|
|
|
|
* - preDelete(\OCP\Files\Node $node)
|
|
|
|
* - postDelete(\OCP\Files\Node $node)
|
|
|
|
* - preTouch(\OC\FilesP\Node $node, int $mtime)
|
|
|
|
* - postTouch(\OCP\Files\Node $node)
|
|
|
|
* - preCopy(\OCP\Files\Node $source, \OCP\Files\Node $target)
|
|
|
|
* - postCopy(\OCP\Files\Node $source, \OCP\Files\Node $target)
|
|
|
|
* - preRename(\OCP\Files\Node $source, \OCP\Files\Node $target)
|
|
|
|
* - postRename(\OCP\Files\Node $source, \OCP\Files\Node $target)
|
2013-09-01 21:47:48 +04:00
|
|
|
*
|
|
|
|
* @package OC\Files\Node
|
|
|
|
*/
|
2014-12-20 17:59:31 +03:00
|
|
|
class Root extends Folder implements IRootFolder {
|
2016-11-03 01:16:51 +03:00
|
|
|
/** @var Manager */
|
2013-09-01 21:47:48 +04:00
|
|
|
private $mountManager;
|
2016-11-03 01:16:51 +03:00
|
|
|
/** @var PublicEmitter */
|
2013-09-01 21:47:48 +04:00
|
|
|
private $emitter;
|
2016-11-03 01:16:51 +03:00
|
|
|
/** @var null|\OC\User\User */
|
2013-09-01 21:47:48 +04:00
|
|
|
private $user;
|
2016-11-03 01:16:51 +03:00
|
|
|
/** @var CappedMemoryCache */
|
2016-08-25 16:49:36 +03:00
|
|
|
private $userFolderCache;
|
2016-11-03 01:16:51 +03:00
|
|
|
/** @var IUserMountCache */
|
2016-09-18 19:36:53 +03:00
|
|
|
private $userMountCache;
|
2016-11-03 01:16:51 +03:00
|
|
|
/** @var ILogger */
|
|
|
|
private $logger;
|
|
|
|
/** @var IUserManager */
|
|
|
|
private $userManager;
|
2016-09-18 19:36:53 +03:00
|
|
|
|
2013-09-01 21:47:48 +04:00
|
|
|
/**
|
|
|
|
* @param \OC\Files\Mount\Manager $manager
|
|
|
|
* @param \OC\Files\View $view
|
2016-02-18 15:55:28 +03:00
|
|
|
* @param \OC\User\User|null $user
|
2016-09-18 19:36:53 +03:00
|
|
|
* @param IUserMountCache $userMountCache
|
2016-11-03 01:16:51 +03:00
|
|
|
* @param ILogger $logger
|
|
|
|
* @param IUserManager $userManager
|
|
|
|
*/
|
|
|
|
public function __construct($manager,
|
|
|
|
$view,
|
|
|
|
$user,
|
|
|
|
IUserMountCache $userMountCache,
|
|
|
|
ILogger $logger,
|
|
|
|
IUserManager $userManager) {
|
2013-09-01 21:47:48 +04:00
|
|
|
parent::__construct($this, $view, '');
|
|
|
|
$this->mountManager = $manager;
|
|
|
|
$this->user = $user;
|
|
|
|
$this->emitter = new PublicEmitter();
|
2016-08-25 16:49:36 +03:00
|
|
|
$this->userFolderCache = new CappedMemoryCache();
|
2016-09-18 19:36:53 +03:00
|
|
|
$this->userMountCache = $userMountCache;
|
2016-11-03 01:16:51 +03:00
|
|
|
$this->logger = $logger;
|
|
|
|
$this->userManager = $userManager;
|
2013-09-01 21:47:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the user for which the filesystem is setup
|
|
|
|
*
|
|
|
|
* @return \OC\User\User
|
|
|
|
*/
|
|
|
|
public function getUser() {
|
|
|
|
return $this->user;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $scope
|
|
|
|
* @param string $method
|
|
|
|
* @param callable $callback
|
|
|
|
*/
|
2015-05-08 15:27:22 +03:00
|
|
|
public function listen($scope, $method, callable $callback) {
|
2013-09-01 21:47:48 +04:00
|
|
|
$this->emitter->listen($scope, $method, $callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $scope optional
|
|
|
|
* @param string $method optional
|
|
|
|
* @param callable $callback optional
|
|
|
|
*/
|
2015-05-08 15:27:22 +03:00
|
|
|
public function removeListener($scope = null, $method = null, callable $callback = null) {
|
2013-09-01 21:47:48 +04:00
|
|
|
$this->emitter->removeListener($scope, $method, $callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $scope
|
|
|
|
* @param string $method
|
2014-02-06 19:30:58 +04:00
|
|
|
* @param Node[] $arguments
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
2020-03-26 11:30:18 +03:00
|
|
|
public function emit($scope, $method, $arguments = []) {
|
2013-09-01 21:47:48 +04:00
|
|
|
$this->emitter->emit($scope, $method, $arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \OC\Files\Storage\Storage $storage
|
|
|
|
* @param string $mountPoint
|
|
|
|
* @param array $arguments
|
|
|
|
*/
|
2020-03-26 11:30:18 +03:00
|
|
|
public function mount($storage, $mountPoint, $arguments = []) {
|
2014-11-24 17:54:42 +03:00
|
|
|
$mount = new MountPoint($storage, $mountPoint, $arguments);
|
2013-09-01 21:47:48 +04:00
|
|
|
$this->mountManager->addMount($mount);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $mountPoint
|
2014-11-24 17:54:42 +03:00
|
|
|
* @return \OC\Files\Mount\MountPoint
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function getMount($mountPoint) {
|
|
|
|
return $this->mountManager->find($mountPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $mountPoint
|
2014-11-24 17:54:42 +03:00
|
|
|
* @return \OC\Files\Mount\MountPoint[]
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function getMountsIn($mountPoint) {
|
|
|
|
return $this->mountManager->findIn($mountPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $storageId
|
2014-11-24 17:54:42 +03:00
|
|
|
* @return \OC\Files\Mount\MountPoint[]
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function getMountByStorageId($storageId) {
|
|
|
|
return $this->mountManager->findByStorageId($storageId);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $numericId
|
2014-11-24 17:54:42 +03:00
|
|
|
* @return MountPoint[]
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function getMountByNumericStorageId($numericId) {
|
|
|
|
return $this->mountManager->findByNumericId($numericId);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-24 17:54:42 +03:00
|
|
|
* @param \OC\Files\Mount\MountPoint $mount
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function unMount($mount) {
|
|
|
|
$this->mountManager->remove($mount);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $path
|
2013-09-10 21:44:23 +04:00
|
|
|
* @throws \OCP\Files\NotFoundException
|
|
|
|
* @throws \OCP\Files\NotPermittedException
|
2016-02-05 12:38:43 +03:00
|
|
|
* @return string
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function get($path) {
|
|
|
|
$path = $this->normalizePath($path);
|
|
|
|
if ($this->isValidPath($path)) {
|
|
|
|
$fullPath = $this->getFullPath($path);
|
2016-02-18 17:36:38 +03:00
|
|
|
$fileInfo = $this->view->getFileInfo($fullPath);
|
|
|
|
if ($fileInfo) {
|
|
|
|
return $this->createNode($fullPath, $fileInfo);
|
2013-09-01 21:47:48 +04:00
|
|
|
} else {
|
2014-08-06 15:38:14 +04:00
|
|
|
throw new NotFoundException($path);
|
2013-09-01 21:47:48 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new NotPermittedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-07 20:51:27 +03:00
|
|
|
//most operations can't be done on the root
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $targetPath
|
2013-09-10 21:44:23 +04:00
|
|
|
* @throws \OCP\Files\NotPermittedException
|
2013-09-01 21:47:48 +04:00
|
|
|
* @return \OC\Files\Node\Node
|
|
|
|
*/
|
|
|
|
public function rename($targetPath) {
|
|
|
|
throw new NotPermittedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete() {
|
|
|
|
throw new NotPermittedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $targetPath
|
2013-09-10 21:44:23 +04:00
|
|
|
* @throws \OCP\Files\NotPermittedException
|
2013-09-01 21:47:48 +04:00
|
|
|
* @return \OC\Files\Node\Node
|
|
|
|
*/
|
|
|
|
public function copy($targetPath) {
|
|
|
|
throw new NotPermittedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $mtime
|
2013-09-10 21:44:23 +04:00
|
|
|
* @throws \OCP\Files\NotPermittedException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function touch($mtime = null) {
|
|
|
|
throw new NotPermittedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \OC\Files\Storage\Storage
|
2013-09-10 21:44:23 +04:00
|
|
|
* @throws \OCP\Files\NotFoundException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function getStorage() {
|
|
|
|
throw new NotFoundException();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getPath() {
|
|
|
|
return '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getInternalPath() {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getId() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function stat() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getMTime() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-27 17:35:44 +03:00
|
|
|
* @param bool $includeMounts
|
2013-09-01 21:47:48 +04:00
|
|
|
* @return int
|
|
|
|
*/
|
2019-02-27 17:35:44 +03:00
|
|
|
public function getSize($includeMounts = true) {
|
2013-09-01 21:47:48 +04:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getEtag() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getPermissions() {
|
2014-11-25 18:28:41 +03:00
|
|
|
return \OCP\Constants::PERMISSION_CREATE;
|
2013-09-01 21:47:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isReadable() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isUpdateable() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isDeletable() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isShareable() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Node
|
2013-09-10 21:44:23 +04:00
|
|
|
* @throws \OCP\Files\NotFoundException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function getParent() {
|
|
|
|
throw new NotFoundException();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getName() {
|
|
|
|
return '';
|
|
|
|
}
|
2015-06-16 17:02:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a view to user's files folder
|
|
|
|
*
|
2018-11-15 13:51:28 +03:00
|
|
|
* @param string $userId user ID
|
2015-06-16 17:02:30 +03:00
|
|
|
* @return \OCP\Files\Folder
|
2020-04-03 13:17:47 +03:00
|
|
|
* @throws NoUserException
|
|
|
|
* @throws NotPermittedException
|
2015-06-16 17:02:30 +03:00
|
|
|
*/
|
|
|
|
public function getUserFolder($userId) {
|
2016-11-03 01:16:51 +03:00
|
|
|
$userObject = $this->userManager->get($userId);
|
2016-10-04 13:28:41 +03:00
|
|
|
|
|
|
|
if (is_null($userObject)) {
|
2016-11-03 01:16:51 +03:00
|
|
|
$this->logger->error(
|
|
|
|
sprintf(
|
|
|
|
'Backends provided no user object for %s',
|
|
|
|
$userId
|
|
|
|
),
|
|
|
|
[
|
|
|
|
'app' => 'files',
|
|
|
|
]
|
|
|
|
);
|
2020-04-03 13:17:47 +03:00
|
|
|
throw new NoUserException('Backends provided no user object');
|
2016-10-04 13:28:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$userId = $userObject->getUID();
|
|
|
|
|
2016-08-25 16:49:36 +03:00
|
|
|
if (!$this->userFolderCache->hasKey($userId)) {
|
|
|
|
\OC\Files\Filesystem::initMountPoints($userId);
|
|
|
|
|
|
|
|
try {
|
2016-08-25 16:50:02 +03:00
|
|
|
$folder = $this->get('/' . $userId . '/files');
|
2016-08-25 16:49:36 +03:00
|
|
|
} catch (NotFoundException $e) {
|
2016-08-25 16:50:02 +03:00
|
|
|
if (!$this->nodeExists('/' . $userId)) {
|
|
|
|
$this->newFolder('/' . $userId);
|
|
|
|
}
|
|
|
|
$folder = $this->newFolder('/' . $userId . '/files');
|
2016-08-25 16:49:36 +03:00
|
|
|
}
|
2016-08-25 16:50:02 +03:00
|
|
|
|
2016-08-25 16:49:36 +03:00
|
|
|
$this->userFolderCache->set($userId, $folder);
|
2015-06-16 17:02:30 +03:00
|
|
|
}
|
|
|
|
|
2016-08-25 16:49:36 +03:00
|
|
|
return $this->userFolderCache->get($userId);
|
|
|
|
}
|
2015-06-16 17:02:30 +03:00
|
|
|
|
2016-08-25 16:49:36 +03:00
|
|
|
public function clearCache() {
|
|
|
|
$this->userFolderCache = new CappedMemoryCache();
|
2015-06-16 17:02:30 +03:00
|
|
|
}
|
2016-09-18 19:36:53 +03:00
|
|
|
|
|
|
|
public function getUserMountCache() {
|
|
|
|
return $this->userMountCache;
|
|
|
|
}
|
2013-09-01 21:47:48 +04:00
|
|
|
}
|