diff options
author | Roeland Jago Douma <rullzer@owncloud.com> | 2016-04-24 19:45:43 +0200 |
---|---|---|
committer | Roeland Jago Douma <rullzer@owncloud.com> | 2016-04-24 21:37:35 +0200 |
commit | dedf392751e1b27163f9dd49b2a54f410727c823 (patch) | |
tree | 2d4d0265d7c574caed62dfe25cd718d79141be04 /lib/private/files/node | |
parent | dc5c570d7caa3095a3cb4ab2b5a51bf772d7de4c (diff) | |
download | nextcloud-server-dedf392751e1b27163f9dd49b2a54f410727c823.tar.gz nextcloud-server-dedf392751e1b27163f9dd49b2a54f410727c823.zip |
Move \OC\Files to PSR-4
Diffstat (limited to 'lib/private/files/node')
-rw-r--r-- | lib/private/files/node/file.php | 176 | ||||
-rw-r--r-- | lib/private/files/node/folder.php | 360 | ||||
-rw-r--r-- | lib/private/files/node/hookconnector.php | 164 | ||||
-rw-r--r-- | lib/private/files/node/lazyroot.php | 474 | ||||
-rw-r--r-- | lib/private/files/node/node.php | 383 | ||||
-rw-r--r-- | lib/private/files/node/nonexistingfile.php | 143 | ||||
-rw-r--r-- | lib/private/files/node/nonexistingfolder.php | 172 | ||||
-rw-r--r-- | lib/private/files/node/root.php | 357 |
8 files changed, 0 insertions, 2229 deletions
diff --git a/lib/private/files/node/file.php b/lib/private/files/node/file.php deleted file mode 100644 index 9e0014abb0b..00000000000 --- a/lib/private/files/node/file.php +++ /dev/null @@ -1,176 +0,0 @@ -<?php -/** - * @author Joas Schilling <nickvergessen@owncloud.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <icewind@owncloud.com> - * @author Roeland Jago Douma <rullzer@owncloud.com> - * @author Vincent Petry <pvince81@owncloud.com> - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @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, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace OC\Files\Node; - -use OCP\Files\NotPermittedException; - -class File extends Node implements \OCP\Files\File { - /** - * @return string - * @throws \OCP\Files\NotPermittedException - */ - public function getContent() { - if ($this->checkPermissions(\OCP\Constants::PERMISSION_READ)) { - /** - * @var \OC\Files\Storage\Storage $storage; - */ - return $this->view->file_get_contents($this->path); - } else { - throw new NotPermittedException(); - } - } - - /** - * @param string $data - * @throws \OCP\Files\NotPermittedException - */ - public function putContent($data) { - if ($this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE)) { - $this->sendHooks(array('preWrite')); - $this->view->file_put_contents($this->path, $data); - $this->fileInfo = null; - $this->sendHooks(array('postWrite')); - } else { - throw new NotPermittedException(); - } - } - - /** - * @param string $mode - * @return resource - * @throws \OCP\Files\NotPermittedException - */ - public function fopen($mode) { - $preHooks = array(); - $postHooks = array(); - $requiredPermissions = \OCP\Constants::PERMISSION_READ; - switch ($mode) { - case 'r+': - case 'rb+': - case 'w+': - case 'wb+': - case 'x+': - case 'xb+': - case 'a+': - case 'ab+': - case 'w': - case 'wb': - case 'x': - case 'xb': - case 'a': - case 'ab': - $preHooks[] = 'preWrite'; - $postHooks[] = 'postWrite'; - $requiredPermissions |= \OCP\Constants::PERMISSION_UPDATE; - break; - } - - if ($this->checkPermissions($requiredPermissions)) { - $this->sendHooks($preHooks); - $result = $this->view->fopen($this->path, $mode); - $this->sendHooks($postHooks); - return $result; - } else { - throw new NotPermittedException(); - } - } - - public function delete() { - if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) { - $this->sendHooks(array('preDelete')); - $fileInfo = $this->getFileInfo(); - $this->view->unlink($this->path); - $nonExisting = new NonExistingFile($this->root, $this->view, $this->path, $fileInfo); - $this->root->emit('\OC\Files', 'postDelete', array($nonExisting)); - $this->exists = false; - $this->fileInfo = null; - } else { - throw new NotPermittedException(); - } - } - - /** - * @param string $targetPath - * @throws \OCP\Files\NotPermittedException - * @return \OC\Files\Node\Node - */ - public function copy($targetPath) { - $targetPath = $this->normalizePath($targetPath); - $parent = $this->root->get(dirname($targetPath)); - if ($parent instanceof Folder and $this->isValidPath($targetPath) and $parent->isCreatable()) { - $nonExisting = new NonExistingFile($this->root, $this->view, $targetPath); - $this->root->emit('\OC\Files', 'preCopy', array($this, $nonExisting)); - $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); - $this->view->copy($this->path, $targetPath); - $targetNode = $this->root->get($targetPath); - $this->root->emit('\OC\Files', 'postCopy', array($this, $targetNode)); - $this->root->emit('\OC\Files', 'postWrite', array($targetNode)); - return $targetNode; - } else { - throw new NotPermittedException(); - } - } - - /** - * @param string $targetPath - * @throws \OCP\Files\NotPermittedException - * @return \OC\Files\Node\Node - */ - public function move($targetPath) { - $targetPath = $this->normalizePath($targetPath); - $parent = $this->root->get(dirname($targetPath)); - if ($parent instanceof Folder and $this->isValidPath($targetPath) and $parent->isCreatable()) { - $nonExisting = new NonExistingFile($this->root, $this->view, $targetPath); - $this->root->emit('\OC\Files', 'preRename', array($this, $nonExisting)); - $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); - $this->view->rename($this->path, $targetPath); - $targetNode = $this->root->get($targetPath); - $this->root->emit('\OC\Files', 'postRename', array($this, $targetNode)); - $this->root->emit('\OC\Files', 'postWrite', array($targetNode)); - $this->path = $targetPath; - $this->fileInfo = null; - return $targetNode; - } else { - throw new NotPermittedException(); - } - } - - /** - * @param string $type - * @param bool $raw - * @return string - */ - public function hash($type, $raw = false) { - return $this->view->hash($type, $this->path, $raw); - } - - /** - * @inheritdoc - */ - public function getChecksum() { - return $this->getFileInfo()->getChecksum(); - } -} diff --git a/lib/private/files/node/folder.php b/lib/private/files/node/folder.php deleted file mode 100644 index f4d7dae20a3..00000000000 --- a/lib/private/files/node/folder.php +++ /dev/null @@ -1,360 +0,0 @@ -<?php -/** - * @author Joas Schilling <nickvergessen@owncloud.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <icewind@owncloud.com> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Vincent Petry <pvince81@owncloud.com> - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @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, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace OC\Files\Node; - -use OCP\Files\FileInfo; -use OCP\Files\NotFoundException; -use OCP\Files\NotPermittedException; - -class Folder extends Node implements \OCP\Files\Folder { - /** - * @param string $path path relative to the folder - * @return string - * @throws \OCP\Files\NotPermittedException - */ - public function getFullPath($path) { - if (!$this->isValidPath($path)) { - throw new NotPermittedException(); - } - return $this->path . $this->normalizePath($path); - } - - /** - * @param string $path - * @return string - */ - public function getRelativePath($path) { - if ($this->path === '' or $this->path === '/') { - return $this->normalizePath($path); - } - if ($path === $this->path) { - return '/'; - } else if (strpos($path, $this->path . '/') !== 0) { - return null; - } else { - $path = substr($path, strlen($this->path)); - return $this->normalizePath($path); - } - } - - /** - * check if a node is a (grand-)child of the folder - * - * @param \OC\Files\Node\Node $node - * @return bool - */ - public function isSubNode($node) { - return strpos($node->getPath(), $this->path . '/') === 0; - } - - /** - * get the content of this directory - * - * @throws \OCP\Files\NotFoundException - * @return Node[] - */ - public function getDirectoryListing() { - $folderContent = $this->view->getDirectoryContent($this->path); - - return array_map(function(FileInfo $info) { - if ($info->getMimetype() === 'httpd/unix-directory') { - return new Folder($this->root, $this->view, $info->getPath(), $info); - } else { - return new File($this->root, $this->view, $info->getPath(), $info); - } - }, $folderContent); - } - - /** - * @param string $path - * @param FileInfo $info - * @return File|Folder - */ - protected function createNode($path, FileInfo $info = null) { - if (is_null($info)) { - $isDir = $this->view->is_dir($path); - } else { - $isDir = $info->getType() === FileInfo::TYPE_FOLDER; - } - if ($isDir) { - return new Folder($this->root, $this->view, $path, $info); - } else { - return new File($this->root, $this->view, $path, $info); - } - } - - /** - * Get the node at $path - * - * @param string $path - * @return \OC\Files\Node\Node - * @throws \OCP\Files\NotFoundException - */ - public function get($path) { - return $this->root->get($this->getFullPath($path)); - } - - /** - * @param string $path - * @return bool - */ - public function nodeExists($path) { - try { - $this->get($path); - return true; - } catch (NotFoundException $e) { - return false; - } - } - - /** - * @param string $path - * @return \OC\Files\Node\Folder - * @throws \OCP\Files\NotPermittedException - */ - public function newFolder($path) { - if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { - $fullPath = $this->getFullPath($path); - $nonExisting = new NonExistingFolder($this->root, $this->view, $fullPath); - $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); - $this->root->emit('\OC\Files', 'preCreate', array($nonExisting)); - $this->view->mkdir($fullPath); - $node = new Folder($this->root, $this->view, $fullPath); - $this->root->emit('\OC\Files', 'postWrite', array($node)); - $this->root->emit('\OC\Files', 'postCreate', array($node)); - return $node; - } else { - throw new NotPermittedException(); - } - } - - /** - * @param string $path - * @return \OC\Files\Node\File - * @throws \OCP\Files\NotPermittedException - */ - public function newFile($path) { - if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { - $fullPath = $this->getFullPath($path); - $nonExisting = new NonExistingFile($this->root, $this->view, $fullPath); - $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); - $this->root->emit('\OC\Files', 'preCreate', array($nonExisting)); - $this->view->touch($fullPath); - $node = new File($this->root, $this->view, $fullPath); - $this->root->emit('\OC\Files', 'postWrite', array($node)); - $this->root->emit('\OC\Files', 'postCreate', array($node)); - return $node; - } else { - throw new NotPermittedException(); - } - } - - /** - * search for files with the name matching $query - * - * @param string $query - * @return \OC\Files\Node\Node[] - */ - public function search($query) { - return $this->searchCommon('search', array('%' . $query . '%')); - } - - /** - * search for files by mimetype - * - * @param string $mimetype - * @return Node[] - */ - public function searchByMime($mimetype) { - return $this->searchCommon('searchByMime', array($mimetype)); - } - - /** - * search for files by tag - * - * @param string|int $tag name or tag id - * @param string $userId owner of the tags - * @return Node[] - */ - public function searchByTag($tag, $userId) { - return $this->searchCommon('searchByTag', array($tag, $userId)); - } - - /** - * @param string $method cache method - * @param array $args call args - * @return \OC\Files\Node\Node[] - */ - private function searchCommon($method, $args) { - $files = array(); - $rootLength = strlen($this->path); - $mount = $this->root->getMount($this->path); - $storage = $mount->getStorage(); - $internalPath = $mount->getInternalPath($this->path); - $internalPath = rtrim($internalPath, '/'); - if ($internalPath !== '') { - $internalPath = $internalPath . '/'; - } - $internalRootLength = strlen($internalPath); - - $cache = $storage->getCache(''); - - $results = call_user_func_array(array($cache, $method), $args); - foreach ($results as $result) { - if ($internalRootLength === 0 or substr($result['path'], 0, $internalRootLength) === $internalPath) { - $result['internalPath'] = $result['path']; - $result['path'] = substr($result['path'], $internalRootLength); - $result['storage'] = $storage; - $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); - } - } - - $mounts = $this->root->getMountsIn($this->path); - foreach ($mounts as $mount) { - $storage = $mount->getStorage(); - if ($storage) { - $cache = $storage->getCache(''); - - $relativeMountPoint = substr($mount->getMountPoint(), $rootLength); - $results = call_user_func_array(array($cache, $method), $args); - foreach ($results as $result) { - $result['internalPath'] = $result['path']; - $result['path'] = $relativeMountPoint . $result['path']; - $result['storage'] = $storage; - $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); - } - } - } - - return array_map(function(FileInfo $file) { - return $this->createNode($file->getPath(), $file); - }, $files); - } - - /** - * @param int $id - * @return \OC\Files\Node\Node[] - */ - public function getById($id) { - $mounts = $this->root->getMountsIn($this->path); - $mounts[] = $this->root->getMount($this->path); - // reverse the array so we start with the storage this view is in - // which is the most likely to contain the file we're looking for - $mounts = array_reverse($mounts); - - $nodes = array(); - foreach ($mounts as $mount) { - /** - * @var \OC\Files\Mount\MountPoint $mount - */ - if ($mount->getStorage()) { - $cache = $mount->getStorage()->getCache(); - $internalPath = $cache->getPathById($id); - if (is_string($internalPath)) { - $fullPath = $mount->getMountPoint() . $internalPath; - if (!is_null($path = $this->getRelativePath($fullPath))) { - $nodes[] = $this->get($path); - } - } - } - } - return $nodes; - } - - public function getFreeSpace() { - return $this->view->free_space($this->path); - } - - public function delete() { - if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) { - $this->sendHooks(array('preDelete')); - $fileInfo = $this->getFileInfo(); - $this->view->rmdir($this->path); - $nonExisting = new NonExistingFolder($this->root, $this->view, $this->path, $fileInfo); - $this->root->emit('\OC\Files', 'postDelete', array($nonExisting)); - $this->exists = false; - } else { - throw new NotPermittedException(); - } - } - - /** - * @param string $targetPath - * @throws \OCP\Files\NotPermittedException - * @return \OC\Files\Node\Node - */ - public function copy($targetPath) { - $targetPath = $this->normalizePath($targetPath); - $parent = $this->root->get(dirname($targetPath)); - if ($parent instanceof Folder and $this->isValidPath($targetPath) and $parent->isCreatable()) { - $nonExisting = new NonExistingFolder($this->root, $this->view, $targetPath); - $this->root->emit('\OC\Files', 'preCopy', array($this, $nonExisting)); - $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); - $this->view->copy($this->path, $targetPath); - $targetNode = $this->root->get($targetPath); - $this->root->emit('\OC\Files', 'postCopy', array($this, $targetNode)); - $this->root->emit('\OC\Files', 'postWrite', array($targetNode)); - return $targetNode; - } else { - throw new NotPermittedException(); - } - } - - /** - * @param string $targetPath - * @throws \OCP\Files\NotPermittedException - * @return \OC\Files\Node\Node - */ - public function move($targetPath) { - $targetPath = $this->normalizePath($targetPath); - $parent = $this->root->get(dirname($targetPath)); - if ($parent instanceof Folder and $this->isValidPath($targetPath) and $parent->isCreatable()) { - $nonExisting = new NonExistingFolder($this->root, $this->view, $targetPath); - $this->root->emit('\OC\Files', 'preRename', array($this, $nonExisting)); - $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); - $this->view->rename($this->path, $targetPath); - $targetNode = $this->root->get($targetPath); - $this->root->emit('\OC\Files', 'postRename', array($this, $targetNode)); - $this->root->emit('\OC\Files', 'postWrite', array($targetNode)); - $this->path = $targetPath; - return $targetNode; - } else { - throw new NotPermittedException(); - } - } - - /** - * Add a suffix to the name in case the file exists - * - * @param string $name - * @return string - * @throws NotPermittedException - */ - public function getNonExistingName($name) { - $uniqueName = \OC_Helper::buildNotExistingFileNameForView($this->getPath(), $name, $this->view); - return trim($this->getRelativePath($uniqueName), '/'); - } -} diff --git a/lib/private/files/node/hookconnector.php b/lib/private/files/node/hookconnector.php deleted file mode 100644 index 5c36ca3848e..00000000000 --- a/lib/private/files/node/hookconnector.php +++ /dev/null @@ -1,164 +0,0 @@ -<?php -/** - * @author Robin Appelman <icewind@owncloud.com> - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @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, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace OC\Files\Node; - -use OCP\Files\FileInfo; -use OC\Files\Filesystem; -use OC\Files\View; -use OCP\Util; - -class HookConnector { - /** - * @var Root - */ - private $root; - - /** - * @var View - */ - private $view; - - /** - * @var FileInfo[] - */ - private $deleteMetaCache = []; - - /** - * HookConnector constructor. - * - * @param Root $root - * @param View $view - */ - public function __construct(Root $root, View $view) { - $this->root = $root; - $this->view = $view; - } - - public function viewToNode() { - Util::connectHook('OC_Filesystem', 'write', $this, 'write'); - Util::connectHook('OC_Filesystem', 'post_write', $this, 'postWrite'); - - Util::connectHook('OC_Filesystem', 'create', $this, 'create'); - Util::connectHook('OC_Filesystem', 'post_create', $this, 'postCreate'); - - Util::connectHook('OC_Filesystem', 'delete', $this, 'delete'); - Util::connectHook('OC_Filesystem', 'post_delete', $this, 'postDelete'); - - Util::connectHook('OC_Filesystem', 'rename', $this, 'rename'); - Util::connectHook('OC_Filesystem', 'post_rename', $this, 'postRename'); - - Util::connectHook('OC_Filesystem', 'copy', $this, 'copy'); - Util::connectHook('OC_Filesystem', 'post_copy', $this, 'postCopy'); - - Util::connectHook('OC_Filesystem', 'touch', $this, 'touch'); - Util::connectHook('OC_Filesystem', 'post_touch', $this, 'postTouch'); - } - - public function write($arguments) { - $node = $this->getNodeForPath($arguments['path']); - $this->root->emit('\OC\Files', 'preWrite', [$node]); - } - - public function postWrite($arguments) { - $node = $this->getNodeForPath($arguments['path']); - $this->root->emit('\OC\Files', 'postWrite', [$node]); - } - - public function create($arguments) { - $node = $this->getNodeForPath($arguments['path']); - $this->root->emit('\OC\Files', 'preCreate', [$node]); - } - - public function postCreate($arguments) { - $node = $this->getNodeForPath($arguments['path']); - $this->root->emit('\OC\Files', 'postCreate', [$node]); - } - - public function delete($arguments) { - $node = $this->getNodeForPath($arguments['path']); - $this->deleteMetaCache[$node->getPath()] = $node->getFileInfo(); - $this->root->emit('\OC\Files', 'preDelete', [$node]); - } - - public function postDelete($arguments) { - $node = $this->getNodeForPath($arguments['path']); - unset($this->deleteMetaCache[$node->getPath()]); - $this->root->emit('\OC\Files', 'postDelete', [$node]); - } - - public function touch($arguments) { - $node = $this->getNodeForPath($arguments['path']); - $this->root->emit('\OC\Files', 'preTouch', [$node]); - } - - public function postTouch($arguments) { - $node = $this->getNodeForPath($arguments['path']); - $this->root->emit('\OC\Files', 'postTouch', [$node]); - } - - public function rename($arguments) { - $source = $this->getNodeForPath($arguments['oldpath']); - $target = $this->getNodeForPath($arguments['newpath']); - $this->root->emit('\OC\Files', 'preRename', [$source, $target]); - } - - public function postRename($arguments) { - $source = $this->getNodeForPath($arguments['oldpath']); - $target = $this->getNodeForPath($arguments['newpath']); - $this->root->emit('\OC\Files', 'postRename', [$source, $target]); - } - - public function copy($arguments) { - $source = $this->getNodeForPath($arguments['oldpath']); - $target = $this->getNodeForPath($arguments['newpath']); - $this->root->emit('\OC\Files', 'preCopy', [$source, $target]); - } - - public function postCopy($arguments) { - $source = $this->getNodeForPath($arguments['oldpath']); - $target = $this->getNodeForPath($arguments['newpath']); - $this->root->emit('\OC\Files', 'postCopy', [$source, $target]); - } - - private function getNodeForPath($path) { - $info = Filesystem::getView()->getFileInfo($path); - if (!$info) { - - $fullPath = Filesystem::getView()->getAbsolutePath($path); - if (isset($this->deleteMetaCache[$fullPath])) { - $info = $this->deleteMetaCache[$fullPath]; - } else { - $info = null; - } - if (Filesystem::is_dir($path)) { - return new NonExistingFolder($this->root, $this->view, $fullPath, $info); - } else { - return new NonExistingFile($this->root, $this->view, $fullPath, $info); - } - } - if ($info->getType() === FileInfo::TYPE_FILE) { - return new File($this->root, $this->view, $info->getPath(), $info); - } else { - return new Folder($this->root, $this->view, $info->getPath(), $info); - } - } -} diff --git a/lib/private/files/node/lazyroot.php b/lib/private/files/node/lazyroot.php deleted file mode 100644 index 9661f036579..00000000000 --- a/lib/private/files/node/lazyroot.php +++ /dev/null @@ -1,474 +0,0 @@ -<?php -/** - * @author Roeland Jago Douma <rullzer@owncloud.com> - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @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, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ -namespace OC\Files\Node; - -use OC\Files\Mount\MountPoint; -use OCP\Files\IRootFolder; -use OCP\Files\NotPermittedException; - -/** - * Class LazyRoot - * - * This is a lazy wrapper around the root. So only - * once it is needed this will get initialized. - * - * @package OC\Files\Node - */ -class LazyRoot implements IRootFolder { - /** @var \Closure */ - private $rootFolderClosure; - - /** @var IRootFolder */ - private $rootFolder; - - /** - * LazyRoot constructor. - * - * @param \Closure $rootFolderClosure - */ - public function __construct(\Closure $rootFolderClosure) { - $this->rootFolderClosure = $rootFolderClosure; - } - - /** - * Magic method to first get the real rootFolder and then - * call $method with $args on it - * - * @param $method - * @param $args - * @return mixed - */ - public function __call($method, $args) { - if ($this->rootFolder === null) { - $this->rootFolder = call_user_func($this->rootFolderClosure); - } - - return call_user_func_array([$this->rootFolder, $method], $args); - } - - /** - * @inheritDoc - */ - public function getUser() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function listen($scope, $method, callable $callback) { - $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function removeListener($scope = null, $method = null, callable $callback = null) { - $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function emit($scope, $method, $arguments = array()) { - $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function mount($storage, $mountPoint, $arguments = array()) { - $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getMount($mountPoint) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getMountsIn($mountPoint) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getMountByStorageId($storageId) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getMountByNumericStorageId($numericId) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function unMount($mount) { - $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function get($path) { - $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function rename($targetPath) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function delete() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function copy($targetPath) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function touch($mtime = null) { - $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getStorage() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getPath() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getInternalPath() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getId() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function stat() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getMTime() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getSize() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getEtag() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getPermissions() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function isReadable() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function isUpdateable() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function isDeletable() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function isShareable() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getParent() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getName() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getUserFolder($userId) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getMimetype() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getMimePart() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function isEncrypted() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getType() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function isShared() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function isMounted() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getMountPoint() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getOwner() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getChecksum() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getFullPath($path) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getRelativePath($path) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function isSubNode($node) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getDirectoryListing() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function nodeExists($path) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function newFolder($path) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function newFile($path) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function search($query) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function searchByMime($mimetype) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function searchByTag($tag, $userId) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getById($id) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getFreeSpace() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function isCreatable() { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function getNonExistingName($name) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function move($targetPath) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function lock($type) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function changeLock($targetType) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - /** - * @inheritDoc - */ - public function unlock($type) { - return $this->__call(__FUNCTION__, func_get_args()); - } - - -} diff --git a/lib/private/files/node/node.php b/lib/private/files/node/node.php deleted file mode 100644 index c4fabfc2e2e..00000000000 --- a/lib/private/files/node/node.php +++ /dev/null @@ -1,383 +0,0 @@ -<?php -/** - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @author Joas Schilling <nickvergessen@owncloud.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <icewind@owncloud.com> - * @author Roeland Jago Douma <rullzer@owncloud.com> - * @author Vincent Petry <pvince81@owncloud.com> - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @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, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace OC\Files\Node; - -use OC\Files\Filesystem; -use OCP\Files\FileInfo; -use OCP\Files\InvalidPathException; -use OCP\Files\NotFoundException; -use OCP\Files\NotPermittedException; - -class Node implements \OCP\Files\Node { - /** - * @var \OC\Files\View $view - */ - protected $view; - - /** - * @var \OC\Files\Node\Root $root - */ - protected $root; - - /** - * @var string $path - */ - protected $path; - - /** - * @var \OCP\Files\FileInfo - */ - protected $fileInfo; - - /** - * @param \OC\Files\View $view - * @param \OC\Files\Node\Root $root - * @param string $path - * @param FileInfo $fileInfo - */ - public function __construct($root, $view, $path, $fileInfo = null) { - $this->view = $view; - $this->root = $root; - $this->path = $path; - $this->fileInfo = $fileInfo; - } - - /** - * Returns the matching file info - * - * @return FileInfo - * @throws InvalidPathException - * @throws NotFoundException - */ - public function getFileInfo() { - if (!Filesystem::isValidPath($this->path)) { - throw new InvalidPathException(); - } - if (!$this->fileInfo) { - $fileInfo = $this->view->getFileInfo($this->path); - if ($fileInfo instanceof FileInfo) { - $this->fileInfo = $fileInfo; - } else { - throw new NotFoundException(); - } - } - return $this->fileInfo; - } - - /** - * @param string[] $hooks - */ - protected function sendHooks($hooks) { - foreach ($hooks as $hook) { - $this->root->emit('\OC\Files', $hook, array($this)); - } - } - - /** - * @param int $permissions - * @return bool - */ - protected function checkPermissions($permissions) { - return ($this->getPermissions() & $permissions) === $permissions; - } - - /** - * @param string $targetPath - * @throws \OCP\Files\NotPermittedException - * @return \OC\Files\Node\Node - */ - public function move($targetPath) { - return; - } - - public function delete() { - return; - } - - /** - * @param string $targetPath - * @return \OC\Files\Node\Node - */ - public function copy($targetPath) { - return; - } - - /** - * @param int $mtime - * @throws \OCP\Files\NotPermittedException - */ - public function touch($mtime = null) { - if ($this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE)) { - $this->sendHooks(array('preTouch')); - $this->view->touch($this->path, $mtime); - $this->sendHooks(array('postTouch')); - if ($this->fileInfo) { - if (is_null($mtime)) { - $mtime = time(); - } - $this->fileInfo['mtime'] = $mtime; - } - } else { - throw new NotPermittedException(); - } - } - - /** - * @return \OC\Files\Storage\Storage - * @throws \OCP\Files\NotFoundException - */ - public function getStorage() { - list($storage,) = $this->view->resolvePath($this->path); - return $storage; - } - - /** - * @return string - */ - public function getPath() { - return $this->path; - } - - /** - * @return string - */ - public function getInternalPath() { - list(, $internalPath) = $this->view->resolvePath($this->path); - return $internalPath; - } - - /** - * @return int - * @throws InvalidPathException - * @throws NotFoundException - */ - public function getId() { - return $this->getFileInfo()->getId(); - } - - /** - * @return array - */ - public function stat() { - return $this->view->stat($this->path); - } - - /** - * @return int - * @throws InvalidPathException - * @throws NotFoundException - */ - public function getMTime() { - return $this->getFileInfo()->getMTime(); - } - - /** - * @return int - * @throws InvalidPathException - * @throws NotFoundException - */ - public function getSize() { - return $this->getFileInfo()->getSize(); - } - - /** - * @return string - * @throws InvalidPathException - * @throws NotFoundException - */ - public function getEtag() { - return $this->getFileInfo()->getEtag(); - } - - /** - * @return int - * @throws InvalidPathException - * @throws NotFoundException - */ - public function getPermissions() { - return $this->getFileInfo()->getPermissions(); - } - - /** - * @return bool - * @throws InvalidPathException - * @throws NotFoundException - */ - public function isReadable() { - return $this->getFileInfo()->isReadable(); - } - - /** - * @return bool - * @throws InvalidPathException - * @throws NotFoundException - */ - public function isUpdateable() { - return $this->getFileInfo()->isUpdateable(); - } - - /** - * @return bool - * @throws InvalidPathException - * @throws NotFoundException - */ - public function isDeletable() { - return $this->getFileInfo()->isDeletable(); - } - - /** - * @return bool - * @throws InvalidPathException - * @throws NotFoundException - */ - public function isShareable() { - return $this->getFileInfo()->isShareable(); - } - - /** - * @return bool - * @throws InvalidPathException - * @throws NotFoundException - */ - public function isCreatable() { - return $this->getFileInfo()->isCreatable(); - } - - /** - * @return Node - */ - public function getParent() { - return $this->root->get(dirname($this->path)); - } - - /** - * @return string - */ - public function getName() { - return basename($this->path); - } - - /** - * @param string $path - * @return string - */ - protected function normalizePath($path) { - if ($path === '' or $path === '/') { - return '/'; - } - //no windows style slashes - $path = str_replace('\\', '/', $path); - //add leading slash - if ($path[0] !== '/') { - $path = '/' . $path; - } - //remove duplicate slashes - while (strpos($path, '//') !== false) { - $path = str_replace('//', '/', $path); - } - //remove trailing slash - $path = rtrim($path, '/'); - - return $path; - } - - /** - * check if the requested path is valid - * - * @param string $path - * @return bool - */ - public function isValidPath($path) { - if (!$path || $path[0] !== '/') { - $path = '/' . $path; - } - if (strstr($path, '/../') || strrchr($path, '/') === '/..') { - return false; - } - return true; - } - - public function isMounted() { - return $this->getFileInfo()->isMounted(); - } - - public function isShared() { - return $this->getFileInfo()->isShared(); - } - - public function getMimeType() { - return $this->getFileInfo()->getMimetype(); - } - - public function getMimePart() { - return $this->getFileInfo()->getMimePart(); - } - - public function getType() { - return $this->getFileInfo()->getType(); - } - - public function isEncrypted() { - return $this->getFileInfo()->isEncrypted(); - } - - public function getMountPoint() { - return $this->getFileInfo()->getMountPoint(); - } - - public function getOwner() { - return $this->getFileInfo()->getOwner(); - } - - public function getChecksum() { - return; - } - - /** - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE - * @throws \OCP\Lock\LockedException - */ - public function lock($type) { - $this->view->lockFile($this->path, $type); - } - - /** - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE - * @throws \OCP\Lock\LockedException - */ - public function changeLock($type) { - $this->view->changeLock($this->path, $type); - } - - /** - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE - * @throws \OCP\Lock\LockedException - */ - public function unlock($type) { - $this->view->unlockFile($this->path, $type); - } -} diff --git a/lib/private/files/node/nonexistingfile.php b/lib/private/files/node/nonexistingfile.php deleted file mode 100644 index c1d09bcc491..00000000000 --- a/lib/private/files/node/nonexistingfile.php +++ /dev/null @@ -1,143 +0,0 @@ -<?php -/** - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <icewind@owncloud.com> - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @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, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace OC\Files\Node; - -use OCP\Files\NotFoundException; - -class NonExistingFile extends File { - /** - * @param string $newPath - * @throws \OCP\Files\NotFoundException - */ - public function rename($newPath) { - throw new NotFoundException(); - } - - public function delete() { - throw new NotFoundException(); - } - - public function copy($newPath) { - throw new NotFoundException(); - } - - public function touch($mtime = null) { - throw new NotFoundException(); - } - - public function getId() { - if ($this->fileInfo) { - return parent::getId(); - } else { - throw new NotFoundException(); - } - } - - public function stat() { - throw new NotFoundException(); - } - - public function getMTime() { - if ($this->fileInfo) { - return parent::getMTime(); - } else { - throw new NotFoundException(); - } - } - - public function getSize() { - if ($this->fileInfo) { - return parent::getSize(); - } else { - throw new NotFoundException(); - } - } - - public function getEtag() { - if ($this->fileInfo) { - return parent::getEtag(); - } else { - throw new NotFoundException(); - } - } - - public function getPermissions() { - if ($this->fileInfo) { - return parent::getPermissions(); - } else { - throw new NotFoundException(); - } - } - - public function isReadable() { - if ($this->fileInfo) { - return parent::isReadable(); - } else { - throw new NotFoundException(); - } - } - - public function isUpdateable() { - if ($this->fileInfo) { - return parent::isUpdateable(); - } else { - throw new NotFoundException(); - } - } - - public function isDeletable() { - if ($this->fileInfo) { - return parent::isDeletable(); - } else { - throw new NotFoundException(); - } - } - - public function isShareable() { - if ($this->fileInfo) { - return parent::isShareable(); - } else { - throw new NotFoundException(); - } - } - - public function getContent() { - throw new NotFoundException(); - } - - public function putContent($data) { - throw new NotFoundException(); - } - - public function getMimeType() { - if ($this->fileInfo) { - return parent::getMimeType(); - } else { - throw new NotFoundException(); - } - } - - public function fopen($mode) { - throw new NotFoundException(); - } -} diff --git a/lib/private/files/node/nonexistingfolder.php b/lib/private/files/node/nonexistingfolder.php deleted file mode 100644 index 7d6576f1bd6..00000000000 --- a/lib/private/files/node/nonexistingfolder.php +++ /dev/null @@ -1,172 +0,0 @@ -<?php -/** - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <icewind@owncloud.com> - * @author Vincent Petry <pvince81@owncloud.com> - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @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, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace OC\Files\Node; - -use OCP\Files\NotFoundException; - -class NonExistingFolder extends Folder { - /** - * @param string $newPath - * @throws \OCP\Files\NotFoundException - */ - public function rename($newPath) { - throw new NotFoundException(); - } - - public function delete() { - throw new NotFoundException(); - } - - public function copy($newPath) { - throw new NotFoundException(); - } - - public function touch($mtime = null) { - throw new NotFoundException(); - } - - public function getId() { - if ($this->fileInfo) { - return parent::getId(); - } else { - throw new NotFoundException(); - } - } - - public function stat() { - throw new NotFoundException(); - } - - public function getMTime() { - if ($this->fileInfo) { - return parent::getMTime(); - } else { - throw new NotFoundException(); - } - } - - public function getSize() { - if ($this->fileInfo) { - return parent::getSize(); - } else { - throw new NotFoundException(); - } - } - - public function getEtag() { - if ($this->fileInfo) { - return parent::getEtag(); - } else { - throw new NotFoundException(); - } - } - - public function getPermissions() { - if ($this->fileInfo) { - return parent::getPermissions(); - } else { - throw new NotFoundException(); - } - } - - public function isReadable() { - if ($this->fileInfo) { - return parent::isReadable(); - } else { - throw new NotFoundException(); - } - } - - public function isUpdateable() { - if ($this->fileInfo) { - return parent::isUpdateable(); - } else { - throw new NotFoundException(); - } - } - - public function isDeletable() { - if ($this->fileInfo) { - return parent::isDeletable(); - } else { - throw new NotFoundException(); - } - } - - public function isShareable() { - if ($this->fileInfo) { - return parent::isShareable(); - } else { - throw new NotFoundException(); - } - } - - public function get($path) { - throw new NotFoundException(); - } - - public function getDirectoryListing() { - throw new NotFoundException(); - } - - public function nodeExists($path) { - return false; - } - - public function newFolder($path) { - throw new NotFoundException(); - } - - public function newFile($path) { - throw new NotFoundException(); - } - - public function search($pattern) { - throw new NotFoundException(); - } - - public function searchByMime($mime) { - throw new NotFoundException(); - } - - public function searchByTag($tag, $userId) { - throw new NotFoundException(); - } - - public function getById($id) { - throw new NotFoundException(); - } - - public function getFreeSpace() { - throw new NotFoundException(); - } - - public function isCreatable() { - if ($this->fileInfo) { - return parent::isCreatable(); - } else { - throw new NotFoundException(); - } - } -} diff --git a/lib/private/files/node/root.php b/lib/private/files/node/root.php deleted file mode 100644 index 04866e60b87..00000000000 --- a/lib/private/files/node/root.php +++ /dev/null @@ -1,357 +0,0 @@ -<?php -/** - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @author Joas Schilling <nickvergessen@owncloud.com> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <icewind@owncloud.com> - * @author Roeland Jago Douma <rullzer@owncloud.com> - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @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, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace OC\Files\Node; - -use OC\Files\Mount\Manager; -use OC\Files\Mount\MountPoint; -use OCP\Files\NotFoundException; -use OCP\Files\NotPermittedException; -use OC\Hooks\PublicEmitter; -use OCP\Files\IRootFolder; - -/** - * Class Root - * - * Hooks available in scope \OC\Files - * - 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) - * - * @package OC\Files\Node - */ -class Root extends Folder implements IRootFolder { - - /** - * @var \OC\Files\Mount\Manager $mountManager - */ - private $mountManager; - - /** - * @var \OC\Hooks\PublicEmitter - */ - private $emitter; - - /** - * @var \OC\User\User $user - */ - private $user; - - /** - * @param \OC\Files\Mount\Manager $manager - * @param \OC\Files\View $view - * @param \OC\User\User|null $user - */ - public function __construct($manager, $view, $user) { - parent::__construct($this, $view, ''); - $this->mountManager = $manager; - $this->user = $user; - $this->emitter = new PublicEmitter(); - } - - /** - * 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 - */ - public function listen($scope, $method, callable $callback) { - $this->emitter->listen($scope, $method, $callback); - } - - /** - * @param string $scope optional - * @param string $method optional - * @param callable $callback optional - */ - public function removeListener($scope = null, $method = null, callable $callback = null) { - $this->emitter->removeListener($scope, $method, $callback); - } - - /** - * @param string $scope - * @param string $method - * @param Node[] $arguments - */ - public function emit($scope, $method, $arguments = array()) { - $this->emitter->emit($scope, $method, $arguments); - } - - /** - * @param \OC\Files\Storage\Storage $storage - * @param string $mountPoint - * @param array $arguments - */ - public function mount($storage, $mountPoint, $arguments = array()) { - $mount = new MountPoint($storage, $mountPoint, $arguments); - $this->mountManager->addMount($mount); - } - - /** - * @param string $mountPoint - * @return \OC\Files\Mount\MountPoint - */ - public function getMount($mountPoint) { - return $this->mountManager->find($mountPoint); - } - - /** - * @param string $mountPoint - * @return \OC\Files\Mount\MountPoint[] - */ - public function getMountsIn($mountPoint) { - return $this->mountManager->findIn($mountPoint); - } - - /** - * @param string $storageId - * @return \OC\Files\Mount\MountPoint[] - */ - public function getMountByStorageId($storageId) { - return $this->mountManager->findByStorageId($storageId); - } - - /** - * @param int $numericId - * @return MountPoint[] - */ - public function getMountByNumericStorageId($numericId) { - return $this->mountManager->findByNumericId($numericId); - } - - /** - * @param \OC\Files\Mount\MountPoint $mount - */ - public function unMount($mount) { - $this->mountManager->remove($mount); - } - - /** - * @param string $path - * @throws \OCP\Files\NotFoundException - * @throws \OCP\Files\NotPermittedException - * @return string - */ - public function get($path) { - $path = $this->normalizePath($path); - if ($this->isValidPath($path)) { - $fullPath = $this->getFullPath($path); - $fileInfo = $this->view->getFileInfo($fullPath); - if ($fileInfo) { - return $this->createNode($fullPath, $fileInfo); - } else { - throw new NotFoundException($path); - } - } else { - throw new NotPermittedException(); - } - } - - //most operations can't be done on the root - - /** - * @param string $targetPath - * @throws \OCP\Files\NotPermittedException - * @return \OC\Files\Node\Node - */ - public function rename($targetPath) { - throw new NotPermittedException(); - } - - public function delete() { - throw new NotPermittedException(); - } - - /** - * @param string $targetPath - * @throws \OCP\Files\NotPermittedException - * @return \OC\Files\Node\Node - */ - public function copy($targetPath) { - throw new NotPermittedException(); - } - - /** - * @param int $mtime - * @throws \OCP\Files\NotPermittedException - */ - public function touch($mtime = null) { - throw new NotPermittedException(); - } - - /** - * @return \OC\Files\Storage\Storage - * @throws \OCP\Files\NotFoundException - */ - 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; - } - - /** - * @return int - */ - public function getSize() { - return null; - } - - /** - * @return string - */ - public function getEtag() { - return null; - } - - /** - * @return int - */ - public function getPermissions() { - return \OCP\Constants::PERMISSION_CREATE; - } - - /** - * @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 - * @throws \OCP\Files\NotFoundException - */ - public function getParent() { - throw new NotFoundException(); - } - - /** - * @return string - */ - public function getName() { - return ''; - } - - /** - * Returns a view to user's files folder - * - * @param String $userId user ID - * @return \OCP\Files\Folder - */ - public function getUserFolder($userId) { - \OC\Files\Filesystem::initMountPoints($userId); - $dir = '/' . $userId; - $folder = null; - - try { - $folder = $this->get($dir); - } catch (NotFoundException $e) { - $folder = $this->newFolder($dir); - } - - $dir = '/files'; - try { - $folder = $folder->get($dir); - } catch (NotFoundException $e) { - $folder = $folder->newFolder($dir); - \OC_Util::copySkeleton($userId, $folder); - } - - return $folder; - - } -} |