@@ -24,16 +24,16 @@ |
||
| 24 | 24 | use Sabre\DAV\Tree; |
| 25 | 25 | |
| 26 | 26 | class CachingTree extends Tree { |
| 27 | - /** |
|
| 28 | - * Store a node in the cache |
|
| 29 | - * |
|
| 30 | - * @param Node $node |
|
| 31 | - * @param null|string $path |
|
| 32 | - */ |
|
| 33 | - public function cacheNode(Node $node, $path = null) { |
|
| 34 | - if (is_null($path)) { |
|
| 35 | - $path = $node->getPath(); |
|
| 36 | - } |
|
| 37 | - $this->cache[trim($path, '/')] = $node; |
|
| 38 | - } |
|
| 27 | + /** |
|
| 28 | + * Store a node in the cache |
|
| 29 | + * |
|
| 30 | + * @param Node $node |
|
| 31 | + * @param null|string $path |
|
| 32 | + */ |
|
| 33 | + public function cacheNode(Node $node, $path = null) { |
|
| 34 | + if (is_null($path)) { |
|
| 35 | + $path = $node->getPath(); |
|
| 36 | + } |
|
| 37 | + $this->cache[trim($path, '/')] = $node; |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -33,14 +33,14 @@ |
||
| 33 | 33 | * @see \Sabre\DAV\Server |
| 34 | 34 | */ |
| 35 | 35 | class Server extends \Sabre\DAV\Server { |
| 36 | - /** @var CachingTree $tree */ |
|
| 36 | + /** @var CachingTree $tree */ |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @see \Sabre\DAV\Server |
|
| 40 | - */ |
|
| 41 | - public function __construct($treeOrNode = null) { |
|
| 42 | - parent::__construct($treeOrNode); |
|
| 43 | - self::$exposeVersion = false; |
|
| 44 | - $this->enablePropfindDepthInfinity = true; |
|
| 45 | - } |
|
| 38 | + /** |
|
| 39 | + * @see \Sabre\DAV\Server |
|
| 40 | + */ |
|
| 41 | + public function __construct($treeOrNode = null) { |
|
| 42 | + parent::__construct($treeOrNode); |
|
| 43 | + self::$exposeVersion = false; |
|
| 44 | + $this->enablePropfindDepthInfinity = true; |
|
| 45 | + } |
|
| 46 | 46 | } |
@@ -49,234 +49,234 @@ |
||
| 49 | 49 | use SearchDAV\XML\Order; |
| 50 | 50 | |
| 51 | 51 | class FileSearchBackend implements ISearchBackend { |
| 52 | - /** @var CachingTree */ |
|
| 53 | - private $tree; |
|
| 52 | + /** @var CachingTree */ |
|
| 53 | + private $tree; |
|
| 54 | 54 | |
| 55 | - /** @var IUser */ |
|
| 56 | - private $user; |
|
| 55 | + /** @var IUser */ |
|
| 56 | + private $user; |
|
| 57 | 57 | |
| 58 | - /** @var IRootFolder */ |
|
| 59 | - private $rootFolder; |
|
| 58 | + /** @var IRootFolder */ |
|
| 59 | + private $rootFolder; |
|
| 60 | 60 | |
| 61 | - /** @var IManager */ |
|
| 62 | - private $shareManager; |
|
| 61 | + /** @var IManager */ |
|
| 62 | + private $shareManager; |
|
| 63 | 63 | |
| 64 | - /** @var View */ |
|
| 65 | - private $view; |
|
| 64 | + /** @var View */ |
|
| 65 | + private $view; |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * FileSearchBackend constructor. |
|
| 69 | - * |
|
| 70 | - * @param CachingTree $tree |
|
| 71 | - * @param IUser $user |
|
| 72 | - * @param IRootFolder $rootFolder |
|
| 73 | - * @param IManager $shareManager |
|
| 74 | - * @param View $view |
|
| 75 | - * @internal param IRootFolder $rootFolder |
|
| 76 | - */ |
|
| 77 | - public function __construct(CachingTree $tree, IUser $user, IRootFolder $rootFolder, IManager $shareManager, View $view) { |
|
| 78 | - $this->tree = $tree; |
|
| 79 | - $this->user = $user; |
|
| 80 | - $this->rootFolder = $rootFolder; |
|
| 81 | - $this->shareManager = $shareManager; |
|
| 82 | - $this->view = $view; |
|
| 83 | - } |
|
| 67 | + /** |
|
| 68 | + * FileSearchBackend constructor. |
|
| 69 | + * |
|
| 70 | + * @param CachingTree $tree |
|
| 71 | + * @param IUser $user |
|
| 72 | + * @param IRootFolder $rootFolder |
|
| 73 | + * @param IManager $shareManager |
|
| 74 | + * @param View $view |
|
| 75 | + * @internal param IRootFolder $rootFolder |
|
| 76 | + */ |
|
| 77 | + public function __construct(CachingTree $tree, IUser $user, IRootFolder $rootFolder, IManager $shareManager, View $view) { |
|
| 78 | + $this->tree = $tree; |
|
| 79 | + $this->user = $user; |
|
| 80 | + $this->rootFolder = $rootFolder; |
|
| 81 | + $this->shareManager = $shareManager; |
|
| 82 | + $this->view = $view; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Search endpoint will be remote.php/dav |
|
| 87 | - * |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 90 | - public function getArbiterPath() { |
|
| 91 | - return ''; |
|
| 92 | - } |
|
| 85 | + /** |
|
| 86 | + * Search endpoint will be remote.php/dav |
|
| 87 | + * |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | + public function getArbiterPath() { |
|
| 91 | + return ''; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - public function isValidScope($href, $depth, $path) { |
|
| 95 | - // only allow scopes inside the dav server |
|
| 96 | - if (is_null($path)) { |
|
| 97 | - return false; |
|
| 98 | - } |
|
| 94 | + public function isValidScope($href, $depth, $path) { |
|
| 95 | + // only allow scopes inside the dav server |
|
| 96 | + if (is_null($path)) { |
|
| 97 | + return false; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - try { |
|
| 101 | - $node = $this->tree->getNodeForPath($path); |
|
| 102 | - return $node instanceof Directory; |
|
| 103 | - } catch (NotFound $e) { |
|
| 104 | - return false; |
|
| 105 | - } |
|
| 106 | - } |
|
| 100 | + try { |
|
| 101 | + $node = $this->tree->getNodeForPath($path); |
|
| 102 | + return $node instanceof Directory; |
|
| 103 | + } catch (NotFound $e) { |
|
| 104 | + return false; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - public function getPropertyDefinitionsForScope($href, $path) { |
|
| 109 | - // all valid scopes support the same schema |
|
| 108 | + public function getPropertyDefinitionsForScope($href, $path) { |
|
| 109 | + // all valid scopes support the same schema |
|
| 110 | 110 | |
| 111 | - //todo dynamically load all propfind properties that are supported |
|
| 112 | - return [ |
|
| 113 | - // queryable properties |
|
| 114 | - new SearchPropertyDefinition('{DAV:}displayname', true, false, true), |
|
| 115 | - new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true), |
|
| 116 | - new SearchPropertyDefinition('{DAV:}getlastmodified', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME), |
|
| 117 | - new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), |
|
| 118 | - new SearchPropertyDefinition(TagsPlugin::FAVORITE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_BOOLEAN), |
|
| 119 | - new SearchPropertyDefinition(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, true, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), |
|
| 111 | + //todo dynamically load all propfind properties that are supported |
|
| 112 | + return [ |
|
| 113 | + // queryable properties |
|
| 114 | + new SearchPropertyDefinition('{DAV:}displayname', true, false, true), |
|
| 115 | + new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true), |
|
| 116 | + new SearchPropertyDefinition('{DAV:}getlastmodified', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME), |
|
| 117 | + new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), |
|
| 118 | + new SearchPropertyDefinition(TagsPlugin::FAVORITE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_BOOLEAN), |
|
| 119 | + new SearchPropertyDefinition(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, true, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), |
|
| 120 | 120 | |
| 121 | - // select only properties |
|
| 122 | - new SearchPropertyDefinition('{DAV:}resourcetype', false, true, false), |
|
| 123 | - new SearchPropertyDefinition('{DAV:}getcontentlength', false, true, false), |
|
| 124 | - new SearchPropertyDefinition(FilesPlugin::CHECKSUMS_PROPERTYNAME, false, true, false), |
|
| 125 | - new SearchPropertyDefinition(FilesPlugin::PERMISSIONS_PROPERTYNAME, false, true, false), |
|
| 126 | - new SearchPropertyDefinition(FilesPlugin::GETETAG_PROPERTYNAME, false, true, false), |
|
| 127 | - new SearchPropertyDefinition(FilesPlugin::OWNER_ID_PROPERTYNAME, false, true, false), |
|
| 128 | - new SearchPropertyDefinition(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME, false, true, false), |
|
| 129 | - new SearchPropertyDefinition(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME, false, true, false), |
|
| 130 | - new SearchPropertyDefinition(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_BOOLEAN), |
|
| 131 | - new SearchPropertyDefinition(FilesPlugin::FILEID_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), |
|
| 132 | - ]; |
|
| 133 | - } |
|
| 121 | + // select only properties |
|
| 122 | + new SearchPropertyDefinition('{DAV:}resourcetype', false, true, false), |
|
| 123 | + new SearchPropertyDefinition('{DAV:}getcontentlength', false, true, false), |
|
| 124 | + new SearchPropertyDefinition(FilesPlugin::CHECKSUMS_PROPERTYNAME, false, true, false), |
|
| 125 | + new SearchPropertyDefinition(FilesPlugin::PERMISSIONS_PROPERTYNAME, false, true, false), |
|
| 126 | + new SearchPropertyDefinition(FilesPlugin::GETETAG_PROPERTYNAME, false, true, false), |
|
| 127 | + new SearchPropertyDefinition(FilesPlugin::OWNER_ID_PROPERTYNAME, false, true, false), |
|
| 128 | + new SearchPropertyDefinition(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME, false, true, false), |
|
| 129 | + new SearchPropertyDefinition(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME, false, true, false), |
|
| 130 | + new SearchPropertyDefinition(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_BOOLEAN), |
|
| 131 | + new SearchPropertyDefinition(FilesPlugin::FILEID_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), |
|
| 132 | + ]; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * @param BasicSearch $search |
|
| 137 | - * @return SearchResult[] |
|
| 138 | - */ |
|
| 139 | - public function search(BasicSearch $search) { |
|
| 140 | - if (count($search->from) !== 1) { |
|
| 141 | - throw new \InvalidArgumentException('Searching more than one folder is not supported'); |
|
| 142 | - } |
|
| 143 | - $query = $this->transformQuery($search); |
|
| 144 | - $scope = $search->from[0]; |
|
| 145 | - if ($scope->path === null) { |
|
| 146 | - throw new \InvalidArgumentException('Using uri\'s as scope is not supported, please use a path relative to the search arbiter instead'); |
|
| 147 | - } |
|
| 148 | - $node = $this->tree->getNodeForPath($scope->path); |
|
| 149 | - if (!$node instanceof Directory) { |
|
| 150 | - throw new \InvalidArgumentException('Search is only supported on directories'); |
|
| 151 | - } |
|
| 135 | + /** |
|
| 136 | + * @param BasicSearch $search |
|
| 137 | + * @return SearchResult[] |
|
| 138 | + */ |
|
| 139 | + public function search(BasicSearch $search) { |
|
| 140 | + if (count($search->from) !== 1) { |
|
| 141 | + throw new \InvalidArgumentException('Searching more than one folder is not supported'); |
|
| 142 | + } |
|
| 143 | + $query = $this->transformQuery($search); |
|
| 144 | + $scope = $search->from[0]; |
|
| 145 | + if ($scope->path === null) { |
|
| 146 | + throw new \InvalidArgumentException('Using uri\'s as scope is not supported, please use a path relative to the search arbiter instead'); |
|
| 147 | + } |
|
| 148 | + $node = $this->tree->getNodeForPath($scope->path); |
|
| 149 | + if (!$node instanceof Directory) { |
|
| 150 | + throw new \InvalidArgumentException('Search is only supported on directories'); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - $fileInfo = $node->getFileInfo(); |
|
| 154 | - $folder = $this->rootFolder->get($fileInfo->getPath()); |
|
| 155 | - /** @var Folder $folder $results */ |
|
| 156 | - $results = $folder->search($query); |
|
| 153 | + $fileInfo = $node->getFileInfo(); |
|
| 154 | + $folder = $this->rootFolder->get($fileInfo->getPath()); |
|
| 155 | + /** @var Folder $folder $results */ |
|
| 156 | + $results = $folder->search($query); |
|
| 157 | 157 | |
| 158 | - return array_map(function (Node $node) { |
|
| 159 | - if ($node instanceof Folder) { |
|
| 160 | - $davNode = new \OCA\DAV\Connector\Sabre\Directory($this->view, $node, $this->tree, $this->shareManager); |
|
| 161 | - } else { |
|
| 162 | - $davNode = new \OCA\DAV\Connector\Sabre\File($this->view, $node, $this->shareManager); |
|
| 163 | - } |
|
| 164 | - $path = $this->getHrefForNode($node); |
|
| 165 | - $this->tree->cacheNode($davNode, $path); |
|
| 166 | - return new SearchResult($davNode, $path); |
|
| 167 | - }, $results); |
|
| 168 | - } |
|
| 158 | + return array_map(function (Node $node) { |
|
| 159 | + if ($node instanceof Folder) { |
|
| 160 | + $davNode = new \OCA\DAV\Connector\Sabre\Directory($this->view, $node, $this->tree, $this->shareManager); |
|
| 161 | + } else { |
|
| 162 | + $davNode = new \OCA\DAV\Connector\Sabre\File($this->view, $node, $this->shareManager); |
|
| 163 | + } |
|
| 164 | + $path = $this->getHrefForNode($node); |
|
| 165 | + $this->tree->cacheNode($davNode, $path); |
|
| 166 | + return new SearchResult($davNode, $path); |
|
| 167 | + }, $results); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * @param Node $node |
|
| 172 | - * @return string |
|
| 173 | - */ |
|
| 174 | - private function getHrefForNode(Node $node) { |
|
| 175 | - $base = '/files/' . $this->user->getUID(); |
|
| 176 | - return $base . $this->view->getRelativePath($node->getPath()); |
|
| 177 | - } |
|
| 170 | + /** |
|
| 171 | + * @param Node $node |
|
| 172 | + * @return string |
|
| 173 | + */ |
|
| 174 | + private function getHrefForNode(Node $node) { |
|
| 175 | + $base = '/files/' . $this->user->getUID(); |
|
| 176 | + return $base . $this->view->getRelativePath($node->getPath()); |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - /** |
|
| 180 | - * @param BasicSearch $query |
|
| 181 | - * @return ISearchQuery |
|
| 182 | - */ |
|
| 183 | - private function transformQuery(BasicSearch $query) { |
|
| 184 | - // TODO offset, limit |
|
| 185 | - $orders = array_map([$this, 'mapSearchOrder'], $query->orderBy); |
|
| 186 | - return new SearchQuery($this->transformSearchOperation($query->where), 0, 0, $orders, $this->user); |
|
| 187 | - } |
|
| 179 | + /** |
|
| 180 | + * @param BasicSearch $query |
|
| 181 | + * @return ISearchQuery |
|
| 182 | + */ |
|
| 183 | + private function transformQuery(BasicSearch $query) { |
|
| 184 | + // TODO offset, limit |
|
| 185 | + $orders = array_map([$this, 'mapSearchOrder'], $query->orderBy); |
|
| 186 | + return new SearchQuery($this->transformSearchOperation($query->where), 0, 0, $orders, $this->user); |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * @param Order $order |
|
| 191 | - * @return ISearchOrder |
|
| 192 | - */ |
|
| 193 | - private function mapSearchOrder(Order $order) { |
|
| 194 | - return new SearchOrder($order->order === Order::ASC ? ISearchOrder::DIRECTION_ASCENDING : ISearchOrder::DIRECTION_DESCENDING, $this->mapPropertyNameToColumn($order->property)); |
|
| 195 | - } |
|
| 189 | + /** |
|
| 190 | + * @param Order $order |
|
| 191 | + * @return ISearchOrder |
|
| 192 | + */ |
|
| 193 | + private function mapSearchOrder(Order $order) { |
|
| 194 | + return new SearchOrder($order->order === Order::ASC ? ISearchOrder::DIRECTION_ASCENDING : ISearchOrder::DIRECTION_DESCENDING, $this->mapPropertyNameToColumn($order->property)); |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - /** |
|
| 198 | - * @param Operator $operator |
|
| 199 | - * @return ISearchOperator |
|
| 200 | - */ |
|
| 201 | - private function transformSearchOperation(Operator $operator) { |
|
| 202 | - list(, $trimmedType) = explode('}', $operator->type); |
|
| 203 | - switch ($operator->type) { |
|
| 204 | - case Operator::OPERATION_AND: |
|
| 205 | - case Operator::OPERATION_OR: |
|
| 206 | - case Operator::OPERATION_NOT: |
|
| 207 | - $arguments = array_map([$this, 'transformSearchOperation'], $operator->arguments); |
|
| 208 | - return new SearchBinaryOperator($trimmedType, $arguments); |
|
| 209 | - case Operator::OPERATION_EQUAL: |
|
| 210 | - case Operator::OPERATION_GREATER_OR_EQUAL_THAN: |
|
| 211 | - case Operator::OPERATION_GREATER_THAN: |
|
| 212 | - case Operator::OPERATION_LESS_OR_EQUAL_THAN: |
|
| 213 | - case Operator::OPERATION_LESS_THAN: |
|
| 214 | - case Operator::OPERATION_IS_LIKE: |
|
| 215 | - if (count($operator->arguments) !== 2) { |
|
| 216 | - throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation'); |
|
| 217 | - } |
|
| 218 | - if (!is_string($operator->arguments[0])) { |
|
| 219 | - throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property'); |
|
| 220 | - } |
|
| 221 | - if (!($operator->arguments[1] instanceof Literal)) { |
|
| 222 | - throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal'); |
|
| 223 | - } |
|
| 224 | - return new SearchComparison($trimmedType, $this->mapPropertyNameToColumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value)); |
|
| 225 | - case Operator::OPERATION_IS_COLLECTION: |
|
| 226 | - return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE); |
|
| 227 | - default: |
|
| 228 | - throw new \InvalidArgumentException('Unsupported operation ' . $trimmedType . ' (' . $operator->type . ')'); |
|
| 229 | - } |
|
| 230 | - } |
|
| 197 | + /** |
|
| 198 | + * @param Operator $operator |
|
| 199 | + * @return ISearchOperator |
|
| 200 | + */ |
|
| 201 | + private function transformSearchOperation(Operator $operator) { |
|
| 202 | + list(, $trimmedType) = explode('}', $operator->type); |
|
| 203 | + switch ($operator->type) { |
|
| 204 | + case Operator::OPERATION_AND: |
|
| 205 | + case Operator::OPERATION_OR: |
|
| 206 | + case Operator::OPERATION_NOT: |
|
| 207 | + $arguments = array_map([$this, 'transformSearchOperation'], $operator->arguments); |
|
| 208 | + return new SearchBinaryOperator($trimmedType, $arguments); |
|
| 209 | + case Operator::OPERATION_EQUAL: |
|
| 210 | + case Operator::OPERATION_GREATER_OR_EQUAL_THAN: |
|
| 211 | + case Operator::OPERATION_GREATER_THAN: |
|
| 212 | + case Operator::OPERATION_LESS_OR_EQUAL_THAN: |
|
| 213 | + case Operator::OPERATION_LESS_THAN: |
|
| 214 | + case Operator::OPERATION_IS_LIKE: |
|
| 215 | + if (count($operator->arguments) !== 2) { |
|
| 216 | + throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation'); |
|
| 217 | + } |
|
| 218 | + if (!is_string($operator->arguments[0])) { |
|
| 219 | + throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property'); |
|
| 220 | + } |
|
| 221 | + if (!($operator->arguments[1] instanceof Literal)) { |
|
| 222 | + throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal'); |
|
| 223 | + } |
|
| 224 | + return new SearchComparison($trimmedType, $this->mapPropertyNameToColumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value)); |
|
| 225 | + case Operator::OPERATION_IS_COLLECTION: |
|
| 226 | + return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE); |
|
| 227 | + default: |
|
| 228 | + throw new \InvalidArgumentException('Unsupported operation ' . $trimmedType . ' (' . $operator->type . ')'); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - /** |
|
| 233 | - * @param string $propertyName |
|
| 234 | - * @return string |
|
| 235 | - */ |
|
| 236 | - private function mapPropertyNameToColumn($propertyName) { |
|
| 237 | - switch ($propertyName) { |
|
| 238 | - case '{DAV:}displayname': |
|
| 239 | - return 'name'; |
|
| 240 | - case '{DAV:}getcontenttype': |
|
| 241 | - return 'mimetype'; |
|
| 242 | - case '{DAV:}getlastmodified': |
|
| 243 | - return 'mtime'; |
|
| 244 | - case FilesPlugin::SIZE_PROPERTYNAME: |
|
| 245 | - return 'size'; |
|
| 246 | - case TagsPlugin::FAVORITE_PROPERTYNAME: |
|
| 247 | - return 'favorite'; |
|
| 248 | - case TagsPlugin::TAGS_PROPERTYNAME: |
|
| 249 | - return 'tagname'; |
|
| 250 | - case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME: |
|
| 251 | - return 'fileid'; |
|
| 252 | - default: |
|
| 253 | - throw new \InvalidArgumentException('Unsupported property for search or order: ' . $propertyName); |
|
| 254 | - } |
|
| 255 | - } |
|
| 232 | + /** |
|
| 233 | + * @param string $propertyName |
|
| 234 | + * @return string |
|
| 235 | + */ |
|
| 236 | + private function mapPropertyNameToColumn($propertyName) { |
|
| 237 | + switch ($propertyName) { |
|
| 238 | + case '{DAV:}displayname': |
|
| 239 | + return 'name'; |
|
| 240 | + case '{DAV:}getcontenttype': |
|
| 241 | + return 'mimetype'; |
|
| 242 | + case '{DAV:}getlastmodified': |
|
| 243 | + return 'mtime'; |
|
| 244 | + case FilesPlugin::SIZE_PROPERTYNAME: |
|
| 245 | + return 'size'; |
|
| 246 | + case TagsPlugin::FAVORITE_PROPERTYNAME: |
|
| 247 | + return 'favorite'; |
|
| 248 | + case TagsPlugin::TAGS_PROPERTYNAME: |
|
| 249 | + return 'tagname'; |
|
| 250 | + case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME: |
|
| 251 | + return 'fileid'; |
|
| 252 | + default: |
|
| 253 | + throw new \InvalidArgumentException('Unsupported property for search or order: ' . $propertyName); |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - private function castValue($propertyName, $value) { |
|
| 258 | - $allProps = $this->getPropertyDefinitionsForScope('', ''); |
|
| 259 | - foreach ($allProps as $prop) { |
|
| 260 | - if ($prop->name === $propertyName) { |
|
| 261 | - $dataType = $prop->dataType; |
|
| 262 | - switch ($dataType) { |
|
| 263 | - case SearchPropertyDefinition::DATATYPE_BOOLEAN: |
|
| 264 | - return $value === 'yes'; |
|
| 265 | - case SearchPropertyDefinition::DATATYPE_DECIMAL: |
|
| 266 | - case SearchPropertyDefinition::DATATYPE_INTEGER: |
|
| 267 | - case SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER: |
|
| 268 | - return 0 + $value; |
|
| 269 | - case SearchPropertyDefinition::DATATYPE_DATETIME: |
|
| 270 | - if (is_numeric($value)) { |
|
| 271 | - return 0 + $value; |
|
| 272 | - } |
|
| 273 | - $date = \DateTime::createFromFormat(\DateTime::ATOM, $value); |
|
| 274 | - return ($date instanceof \DateTime) ? $date->getTimestamp() : 0; |
|
| 275 | - default: |
|
| 276 | - return $value; |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - return $value; |
|
| 281 | - } |
|
| 257 | + private function castValue($propertyName, $value) { |
|
| 258 | + $allProps = $this->getPropertyDefinitionsForScope('', ''); |
|
| 259 | + foreach ($allProps as $prop) { |
|
| 260 | + if ($prop->name === $propertyName) { |
|
| 261 | + $dataType = $prop->dataType; |
|
| 262 | + switch ($dataType) { |
|
| 263 | + case SearchPropertyDefinition::DATATYPE_BOOLEAN: |
|
| 264 | + return $value === 'yes'; |
|
| 265 | + case SearchPropertyDefinition::DATATYPE_DECIMAL: |
|
| 266 | + case SearchPropertyDefinition::DATATYPE_INTEGER: |
|
| 267 | + case SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER: |
|
| 268 | + return 0 + $value; |
|
| 269 | + case SearchPropertyDefinition::DATATYPE_DATETIME: |
|
| 270 | + if (is_numeric($value)) { |
|
| 271 | + return 0 + $value; |
|
| 272 | + } |
|
| 273 | + $date = \DateTime::createFromFormat(\DateTime::ATOM, $value); |
|
| 274 | + return ($date instanceof \DateTime) ? $date->getTimestamp() : 0; |
|
| 275 | + default: |
|
| 276 | + return $value; |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + return $value; |
|
| 281 | + } |
|
| 282 | 282 | } |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | /** @var Folder $folder $results */ |
| 156 | 156 | $results = $folder->search($query); |
| 157 | 157 | |
| 158 | - return array_map(function (Node $node) { |
|
| 158 | + return array_map(function(Node $node) { |
|
| 159 | 159 | if ($node instanceof Folder) { |
| 160 | 160 | $davNode = new \OCA\DAV\Connector\Sabre\Directory($this->view, $node, $this->tree, $this->shareManager); |
| 161 | 161 | } else { |
@@ -172,8 +172,8 @@ discard block |
||
| 172 | 172 | * @return string |
| 173 | 173 | */ |
| 174 | 174 | private function getHrefForNode(Node $node) { |
| 175 | - $base = '/files/' . $this->user->getUID(); |
|
| 176 | - return $base . $this->view->getRelativePath($node->getPath()); |
|
| 175 | + $base = '/files/'.$this->user->getUID(); |
|
| 176 | + return $base.$this->view->getRelativePath($node->getPath()); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -213,19 +213,19 @@ discard block |
||
| 213 | 213 | case Operator::OPERATION_LESS_THAN: |
| 214 | 214 | case Operator::OPERATION_IS_LIKE: |
| 215 | 215 | if (count($operator->arguments) !== 2) { |
| 216 | - throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation'); |
|
| 216 | + throw new \InvalidArgumentException('Invalid number of arguments for '.$trimmedType.' operation'); |
|
| 217 | 217 | } |
| 218 | 218 | if (!is_string($operator->arguments[0])) { |
| 219 | - throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property'); |
|
| 219 | + throw new \InvalidArgumentException('Invalid argument 1 for '.$trimmedType.' operation, expected property'); |
|
| 220 | 220 | } |
| 221 | 221 | if (!($operator->arguments[1] instanceof Literal)) { |
| 222 | - throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal'); |
|
| 222 | + throw new \InvalidArgumentException('Invalid argument 2 for '.$trimmedType.' operation, expected literal'); |
|
| 223 | 223 | } |
| 224 | 224 | return new SearchComparison($trimmedType, $this->mapPropertyNameToColumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value)); |
| 225 | 225 | case Operator::OPERATION_IS_COLLECTION: |
| 226 | 226 | return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE); |
| 227 | 227 | default: |
| 228 | - throw new \InvalidArgumentException('Unsupported operation ' . $trimmedType . ' (' . $operator->type . ')'); |
|
| 228 | + throw new \InvalidArgumentException('Unsupported operation '.$trimmedType.' ('.$operator->type.')'); |
|
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME: |
| 251 | 251 | return 'fileid'; |
| 252 | 252 | default: |
| 253 | - throw new \InvalidArgumentException('Unsupported property for search or order: ' . $propertyName); |
|
| 253 | + throw new \InvalidArgumentException('Unsupported property for search or order: '.$propertyName); |
|
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | |
@@ -59,198 +59,198 @@ |
||
| 59 | 59 | |
| 60 | 60 | class Server { |
| 61 | 61 | |
| 62 | - /** @var IRequest */ |
|
| 63 | - private $request; |
|
| 62 | + /** @var IRequest */ |
|
| 63 | + private $request; |
|
| 64 | 64 | |
| 65 | - /** @var string */ |
|
| 66 | - private $baseUri; |
|
| 65 | + /** @var string */ |
|
| 66 | + private $baseUri; |
|
| 67 | 67 | |
| 68 | - /** @var Connector\Sabre\Server */ |
|
| 69 | - private $server; |
|
| 68 | + /** @var Connector\Sabre\Server */ |
|
| 69 | + private $server; |
|
| 70 | 70 | |
| 71 | - public function __construct(IRequest $request, $baseUri) { |
|
| 72 | - $this->request = $request; |
|
| 73 | - $this->baseUri = $baseUri; |
|
| 74 | - $logger = \OC::$server->getLogger(); |
|
| 75 | - $mailer = \OC::$server->getMailer(); |
|
| 76 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 71 | + public function __construct(IRequest $request, $baseUri) { |
|
| 72 | + $this->request = $request; |
|
| 73 | + $this->baseUri = $baseUri; |
|
| 74 | + $logger = \OC::$server->getLogger(); |
|
| 75 | + $mailer = \OC::$server->getMailer(); |
|
| 76 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 77 | 77 | |
| 78 | - $root = new RootCollection(); |
|
| 79 | - $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
| 78 | + $root = new RootCollection(); |
|
| 79 | + $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
| 80 | 80 | |
| 81 | - // Add maintenance plugin |
|
| 82 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); |
|
| 81 | + // Add maintenance plugin |
|
| 82 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); |
|
| 83 | 83 | |
| 84 | - // Backends |
|
| 85 | - $authBackend = new Auth( |
|
| 86 | - \OC::$server->getSession(), |
|
| 87 | - \OC::$server->getUserSession(), |
|
| 88 | - \OC::$server->getRequest(), |
|
| 89 | - \OC::$server->getTwoFactorAuthManager(), |
|
| 90 | - \OC::$server->getBruteForceThrottler() |
|
| 91 | - ); |
|
| 84 | + // Backends |
|
| 85 | + $authBackend = new Auth( |
|
| 86 | + \OC::$server->getSession(), |
|
| 87 | + \OC::$server->getUserSession(), |
|
| 88 | + \OC::$server->getRequest(), |
|
| 89 | + \OC::$server->getTwoFactorAuthManager(), |
|
| 90 | + \OC::$server->getBruteForceThrottler() |
|
| 91 | + ); |
|
| 92 | 92 | |
| 93 | - // Set URL explicitly due to reverse-proxy situations |
|
| 94 | - $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
| 95 | - $this->server->setBaseUri($this->baseUri); |
|
| 93 | + // Set URL explicitly due to reverse-proxy situations |
|
| 94 | + $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
| 95 | + $this->server->setBaseUri($this->baseUri); |
|
| 96 | 96 | |
| 97 | - $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
| 98 | - $authPlugin = new Plugin(); |
|
| 99 | - $authPlugin->addBackend(new PublicAuth()); |
|
| 100 | - $this->server->addPlugin($authPlugin); |
|
| 97 | + $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
| 98 | + $authPlugin = new Plugin(); |
|
| 99 | + $authPlugin->addBackend(new PublicAuth()); |
|
| 100 | + $this->server->addPlugin($authPlugin); |
|
| 101 | 101 | |
| 102 | - // allow setup of additional auth backends |
|
| 103 | - $event = new SabrePluginEvent($this->server); |
|
| 104 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 102 | + // allow setup of additional auth backends |
|
| 103 | + $event = new SabrePluginEvent($this->server); |
|
| 104 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 105 | 105 | |
| 106 | - $bearerAuthBackend = new BearerAuth( |
|
| 107 | - \OC::$server->getUserSession(), |
|
| 108 | - \OC::$server->getSession(), |
|
| 109 | - \OC::$server->getRequest() |
|
| 110 | - ); |
|
| 111 | - $authPlugin->addBackend($bearerAuthBackend); |
|
| 112 | - // because we are throwing exceptions this plugin has to be the last one |
|
| 113 | - $authPlugin->addBackend($authBackend); |
|
| 106 | + $bearerAuthBackend = new BearerAuth( |
|
| 107 | + \OC::$server->getUserSession(), |
|
| 108 | + \OC::$server->getSession(), |
|
| 109 | + \OC::$server->getRequest() |
|
| 110 | + ); |
|
| 111 | + $authPlugin->addBackend($bearerAuthBackend); |
|
| 112 | + // because we are throwing exceptions this plugin has to be the last one |
|
| 113 | + $authPlugin->addBackend($authBackend); |
|
| 114 | 114 | |
| 115 | - // debugging |
|
| 116 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 117 | - $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 118 | - } else { |
|
| 119 | - $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 120 | - } |
|
| 115 | + // debugging |
|
| 116 | + if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 117 | + $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 118 | + } else { |
|
| 119 | + $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
| 123 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 124 | - $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 122 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
| 123 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 124 | + $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 125 | 125 | |
| 126 | - // acl |
|
| 127 | - $acl = new DavAclPlugin(); |
|
| 128 | - $acl->principalCollectionSet = [ |
|
| 129 | - 'principals/users', 'principals/groups' |
|
| 130 | - ]; |
|
| 131 | - $acl->defaultUsernamePath = 'principals/users'; |
|
| 132 | - $this->server->addPlugin($acl); |
|
| 126 | + // acl |
|
| 127 | + $acl = new DavAclPlugin(); |
|
| 128 | + $acl->principalCollectionSet = [ |
|
| 129 | + 'principals/users', 'principals/groups' |
|
| 130 | + ]; |
|
| 131 | + $acl->defaultUsernamePath = 'principals/users'; |
|
| 132 | + $this->server->addPlugin($acl); |
|
| 133 | 133 | |
| 134 | - // calendar plugins |
|
| 135 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 136 | - $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
| 137 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
| 138 | - $this->server->addPlugin(new IMipPlugin($mailer, $logger)); |
|
| 139 | - $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 140 | - $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 141 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
| 142 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
| 143 | - \OC::$server->getConfig(), |
|
| 144 | - \OC::$server->getURLGenerator() |
|
| 145 | - )); |
|
| 134 | + // calendar plugins |
|
| 135 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 136 | + $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
| 137 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
| 138 | + $this->server->addPlugin(new IMipPlugin($mailer, $logger)); |
|
| 139 | + $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 140 | + $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 141 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
| 142 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
| 143 | + \OC::$server->getConfig(), |
|
| 144 | + \OC::$server->getURLGenerator() |
|
| 145 | + )); |
|
| 146 | 146 | |
| 147 | - // addressbook plugins |
|
| 148 | - $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 149 | - $this->server->addPlugin(new VCFExportPlugin()); |
|
| 150 | - $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache')))); |
|
| 147 | + // addressbook plugins |
|
| 148 | + $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 149 | + $this->server->addPlugin(new VCFExportPlugin()); |
|
| 150 | + $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache')))); |
|
| 151 | 151 | |
| 152 | - // system tags plugins |
|
| 153 | - $this->server->addPlugin(new SystemTagPlugin( |
|
| 154 | - \OC::$server->getSystemTagManager(), |
|
| 155 | - \OC::$server->getGroupManager(), |
|
| 156 | - \OC::$server->getUserSession() |
|
| 157 | - )); |
|
| 152 | + // system tags plugins |
|
| 153 | + $this->server->addPlugin(new SystemTagPlugin( |
|
| 154 | + \OC::$server->getSystemTagManager(), |
|
| 155 | + \OC::$server->getGroupManager(), |
|
| 156 | + \OC::$server->getUserSession() |
|
| 157 | + )); |
|
| 158 | 158 | |
| 159 | - // comments plugin |
|
| 160 | - $this->server->addPlugin(new CommentsPlugin( |
|
| 161 | - \OC::$server->getCommentsManager(), |
|
| 162 | - \OC::$server->getUserSession() |
|
| 163 | - )); |
|
| 159 | + // comments plugin |
|
| 160 | + $this->server->addPlugin(new CommentsPlugin( |
|
| 161 | + \OC::$server->getCommentsManager(), |
|
| 162 | + \OC::$server->getUserSession() |
|
| 163 | + )); |
|
| 164 | 164 | |
| 165 | - $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 165 | + $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 166 | 166 | |
| 167 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 168 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
| 169 | - if($request->isUserAgent([ |
|
| 170 | - '/WebDAVFS/', |
|
| 171 | - '/Microsoft Office OneNote 2013/', |
|
| 172 | - '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
| 173 | - ])) { |
|
| 174 | - $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 175 | - } |
|
| 167 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 168 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
| 169 | + if($request->isUserAgent([ |
|
| 170 | + '/WebDAVFS/', |
|
| 171 | + '/Microsoft Office OneNote 2013/', |
|
| 172 | + '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
| 173 | + ])) { |
|
| 174 | + $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 178 | - $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 179 | - } |
|
| 177 | + if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 178 | + $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - // wait with registering these until auth is handled and the filesystem is setup |
|
| 182 | - $this->server->on('beforeMethod', function () { |
|
| 183 | - // custom properties plugin must be the last one |
|
| 184 | - $userSession = \OC::$server->getUserSession(); |
|
| 185 | - $user = $userSession->getUser(); |
|
| 186 | - if ($user !== null) { |
|
| 187 | - $view = \OC\Files\Filesystem::getView(); |
|
| 188 | - $this->server->addPlugin( |
|
| 189 | - new FilesPlugin( |
|
| 190 | - $this->server->tree, |
|
| 191 | - \OC::$server->getConfig(), |
|
| 192 | - $this->request, |
|
| 193 | - \OC::$server->getPreviewManager(), |
|
| 194 | - false, |
|
| 195 | - !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 196 | - ) |
|
| 197 | - ); |
|
| 181 | + // wait with registering these until auth is handled and the filesystem is setup |
|
| 182 | + $this->server->on('beforeMethod', function () { |
|
| 183 | + // custom properties plugin must be the last one |
|
| 184 | + $userSession = \OC::$server->getUserSession(); |
|
| 185 | + $user = $userSession->getUser(); |
|
| 186 | + if ($user !== null) { |
|
| 187 | + $view = \OC\Files\Filesystem::getView(); |
|
| 188 | + $this->server->addPlugin( |
|
| 189 | + new FilesPlugin( |
|
| 190 | + $this->server->tree, |
|
| 191 | + \OC::$server->getConfig(), |
|
| 192 | + $this->request, |
|
| 193 | + \OC::$server->getPreviewManager(), |
|
| 194 | + false, |
|
| 195 | + !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 196 | + ) |
|
| 197 | + ); |
|
| 198 | 198 | |
| 199 | - $this->server->addPlugin( |
|
| 200 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 201 | - new CustomPropertiesBackend( |
|
| 202 | - $this->server->tree, |
|
| 203 | - \OC::$server->getDatabaseConnection(), |
|
| 204 | - \OC::$server->getUserSession()->getUser() |
|
| 205 | - ) |
|
| 206 | - ) |
|
| 207 | - ); |
|
| 208 | - if ($view !== null) { |
|
| 209 | - $this->server->addPlugin( |
|
| 210 | - new QuotaPlugin($view)); |
|
| 211 | - } |
|
| 212 | - $this->server->addPlugin( |
|
| 213 | - new TagsPlugin( |
|
| 214 | - $this->server->tree, \OC::$server->getTagManager() |
|
| 215 | - ) |
|
| 216 | - ); |
|
| 217 | - // TODO: switch to LazyUserFolder |
|
| 218 | - $userFolder = \OC::$server->getUserFolder(); |
|
| 219 | - $this->server->addPlugin(new SharesPlugin( |
|
| 220 | - $this->server->tree, |
|
| 221 | - $userSession, |
|
| 222 | - $userFolder, |
|
| 223 | - \OC::$server->getShareManager() |
|
| 224 | - )); |
|
| 225 | - $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 226 | - \OC::$server->getCommentsManager(), |
|
| 227 | - $userSession |
|
| 228 | - )); |
|
| 229 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
| 230 | - if ($view !== null) { |
|
| 231 | - $this->server->addPlugin(new FilesReportPlugin( |
|
| 232 | - $this->server->tree, |
|
| 233 | - $view, |
|
| 234 | - \OC::$server->getSystemTagManager(), |
|
| 235 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 236 | - \OC::$server->getTagManager(), |
|
| 237 | - $userSession, |
|
| 238 | - \OC::$server->getGroupManager(), |
|
| 239 | - $userFolder |
|
| 240 | - )); |
|
| 241 | - $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
| 242 | - $this->server->tree, |
|
| 243 | - $user, |
|
| 244 | - \OC::$server->getRootFolder(), |
|
| 245 | - \OC::$server->getShareManager(), |
|
| 246 | - $view |
|
| 247 | - ))); |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - }); |
|
| 251 | - } |
|
| 199 | + $this->server->addPlugin( |
|
| 200 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 201 | + new CustomPropertiesBackend( |
|
| 202 | + $this->server->tree, |
|
| 203 | + \OC::$server->getDatabaseConnection(), |
|
| 204 | + \OC::$server->getUserSession()->getUser() |
|
| 205 | + ) |
|
| 206 | + ) |
|
| 207 | + ); |
|
| 208 | + if ($view !== null) { |
|
| 209 | + $this->server->addPlugin( |
|
| 210 | + new QuotaPlugin($view)); |
|
| 211 | + } |
|
| 212 | + $this->server->addPlugin( |
|
| 213 | + new TagsPlugin( |
|
| 214 | + $this->server->tree, \OC::$server->getTagManager() |
|
| 215 | + ) |
|
| 216 | + ); |
|
| 217 | + // TODO: switch to LazyUserFolder |
|
| 218 | + $userFolder = \OC::$server->getUserFolder(); |
|
| 219 | + $this->server->addPlugin(new SharesPlugin( |
|
| 220 | + $this->server->tree, |
|
| 221 | + $userSession, |
|
| 222 | + $userFolder, |
|
| 223 | + \OC::$server->getShareManager() |
|
| 224 | + )); |
|
| 225 | + $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 226 | + \OC::$server->getCommentsManager(), |
|
| 227 | + $userSession |
|
| 228 | + )); |
|
| 229 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
| 230 | + if ($view !== null) { |
|
| 231 | + $this->server->addPlugin(new FilesReportPlugin( |
|
| 232 | + $this->server->tree, |
|
| 233 | + $view, |
|
| 234 | + \OC::$server->getSystemTagManager(), |
|
| 235 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 236 | + \OC::$server->getTagManager(), |
|
| 237 | + $userSession, |
|
| 238 | + \OC::$server->getGroupManager(), |
|
| 239 | + $userFolder |
|
| 240 | + )); |
|
| 241 | + $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
| 242 | + $this->server->tree, |
|
| 243 | + $user, |
|
| 244 | + \OC::$server->getRootFolder(), |
|
| 245 | + \OC::$server->getShareManager(), |
|
| 246 | + $view |
|
| 247 | + ))); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + }); |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - public function exec() { |
|
| 254 | - $this->server->exec(); |
|
| 255 | - } |
|
| 253 | + public function exec() { |
|
| 254 | + $this->server->exec(); |
|
| 255 | + } |
|
| 256 | 256 | } |
@@ -41,200 +41,200 @@ |
||
| 41 | 41 | |
| 42 | 42 | class ObjectTree extends CachingTree { |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @var \OC\Files\View |
|
| 46 | - */ |
|
| 47 | - protected $fileView; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var \OCP\Files\Mount\IMountManager |
|
| 51 | - */ |
|
| 52 | - protected $mountManager; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Creates the object |
|
| 56 | - */ |
|
| 57 | - public function __construct() { |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @param \Sabre\DAV\INode $rootNode |
|
| 62 | - * @param \OC\Files\View $view |
|
| 63 | - * @param \OCP\Files\Mount\IMountManager $mountManager |
|
| 64 | - */ |
|
| 65 | - public function init(\Sabre\DAV\INode $rootNode, \OC\Files\View $view, \OCP\Files\Mount\IMountManager $mountManager) { |
|
| 66 | - $this->rootNode = $rootNode; |
|
| 67 | - $this->fileView = $view; |
|
| 68 | - $this->mountManager = $mountManager; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * If the given path is a chunked file name, converts it |
|
| 73 | - * to the real file name. Only applies if the OC-CHUNKED header |
|
| 74 | - * is present. |
|
| 75 | - * |
|
| 76 | - * @param string $path chunk file path to convert |
|
| 77 | - * |
|
| 78 | - * @return string path to real file |
|
| 79 | - */ |
|
| 80 | - private function resolveChunkFile($path) { |
|
| 81 | - if (isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
| 82 | - // resolve to real file name to find the proper node |
|
| 83 | - list($dir, $name) = \Sabre\Uri\split($path); |
|
| 84 | - if ($dir === '/' || $dir === '.') { |
|
| 85 | - $dir = ''; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $info = \OC_FileChunking::decodeName($name); |
|
| 89 | - // only replace path if it was really the chunked file |
|
| 90 | - if (isset($info['transferid'])) { |
|
| 91 | - // getNodePath is called for multiple nodes within a chunk |
|
| 92 | - // upload call |
|
| 93 | - $path = $dir . '/' . $info['name']; |
|
| 94 | - $path = ltrim($path, '/'); |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - return $path; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Returns the INode object for the requested path |
|
| 102 | - * |
|
| 103 | - * @param string $path |
|
| 104 | - * @return \Sabre\DAV\INode |
|
| 105 | - * @throws InvalidPath |
|
| 106 | - * @throws \Sabre\DAV\Exception\Locked |
|
| 107 | - * @throws \Sabre\DAV\Exception\NotFound |
|
| 108 | - * @throws \Sabre\DAV\Exception\ServiceUnavailable |
|
| 109 | - */ |
|
| 110 | - public function getNodeForPath($path) { |
|
| 111 | - if (!$this->fileView) { |
|
| 112 | - throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup'); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $path = trim($path, '/'); |
|
| 116 | - |
|
| 117 | - if (isset($this->cache[$path])) { |
|
| 118 | - return $this->cache[$path]; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - if ($path) { |
|
| 122 | - try { |
|
| 123 | - $this->fileView->verifyPath($path, basename($path)); |
|
| 124 | - } catch (\OCP\Files\InvalidPathException $ex) { |
|
| 125 | - throw new InvalidPath($ex->getMessage()); |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - // Is it the root node? |
|
| 130 | - if (!strlen($path)) { |
|
| 131 | - return $this->rootNode; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - if (pathinfo($path, PATHINFO_EXTENSION) === 'part') { |
|
| 135 | - // read from storage |
|
| 136 | - $absPath = $this->fileView->getAbsolutePath($path); |
|
| 137 | - $mount = $this->fileView->getMount($path); |
|
| 138 | - $storage = $mount->getStorage(); |
|
| 139 | - $internalPath = $mount->getInternalPath($absPath); |
|
| 140 | - if ($storage && $storage->file_exists($internalPath)) { |
|
| 141 | - /** |
|
| 142 | - * @var \OC\Files\Storage\Storage $storage |
|
| 143 | - */ |
|
| 144 | - // get data directly |
|
| 145 | - $data = $storage->getMetaData($internalPath); |
|
| 146 | - $info = new FileInfo($absPath, $storage, $internalPath, $data, $mount); |
|
| 147 | - } else { |
|
| 148 | - $info = null; |
|
| 149 | - } |
|
| 150 | - } else { |
|
| 151 | - // resolve chunk file name to real name, if applicable |
|
| 152 | - $path = $this->resolveChunkFile($path); |
|
| 153 | - |
|
| 154 | - // read from cache |
|
| 155 | - try { |
|
| 156 | - $info = $this->fileView->getFileInfo($path); |
|
| 157 | - } catch (StorageNotAvailableException $e) { |
|
| 158 | - throw new \Sabre\DAV\Exception\ServiceUnavailable('Storage is temporarily not available'); |
|
| 159 | - } catch (StorageInvalidException $e) { |
|
| 160 | - throw new \Sabre\DAV\Exception\NotFound('Storage ' . $path . ' is invalid'); |
|
| 161 | - } catch (LockedException $e) { |
|
| 162 | - throw new \Sabre\DAV\Exception\Locked(); |
|
| 163 | - } catch (ForbiddenException $e) { |
|
| 164 | - throw new \Sabre\DAV\Exception\Forbidden(); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - if (!$info) { |
|
| 169 | - throw new \Sabre\DAV\Exception\NotFound('File with name ' . $path . ' could not be located'); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - if ($info->getType() === 'dir') { |
|
| 173 | - $node = new \OCA\DAV\Connector\Sabre\Directory($this->fileView, $info, $this); |
|
| 174 | - } else { |
|
| 175 | - $node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - $this->cache[$path] = $node; |
|
| 179 | - return $node; |
|
| 180 | - |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Copies a file or directory. |
|
| 185 | - * |
|
| 186 | - * This method must work recursively and delete the destination |
|
| 187 | - * if it exists |
|
| 188 | - * |
|
| 189 | - * @param string $source |
|
| 190 | - * @param string $destination |
|
| 191 | - * @throws FileLocked |
|
| 192 | - * @throws Forbidden |
|
| 193 | - * @throws InvalidPath |
|
| 194 | - * @throws \Exception |
|
| 195 | - * @throws \Sabre\DAV\Exception\Forbidden |
|
| 196 | - * @throws \Sabre\DAV\Exception\Locked |
|
| 197 | - * @throws \Sabre\DAV\Exception\NotFound |
|
| 198 | - * @throws \Sabre\DAV\Exception\ServiceUnavailable |
|
| 199 | - * @return void |
|
| 200 | - */ |
|
| 201 | - public function copy($source, $destination) { |
|
| 202 | - if (!$this->fileView) { |
|
| 203 | - throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup'); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - |
|
| 207 | - $info = $this->fileView->getFileInfo(dirname($destination)); |
|
| 208 | - if ($this->fileView->file_exists($destination)) { |
|
| 209 | - $destinationPermission = $info && $info->isUpdateable(); |
|
| 210 | - } else { |
|
| 211 | - $destinationPermission = $info && $info->isCreatable(); |
|
| 212 | - } |
|
| 213 | - if (!$destinationPermission) { |
|
| 214 | - throw new Forbidden('No permissions to copy object.'); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // this will trigger existence check |
|
| 218 | - $this->getNodeForPath($source); |
|
| 219 | - |
|
| 220 | - list($destinationDir, $destinationName) = \Sabre\Uri\split($destination); |
|
| 221 | - try { |
|
| 222 | - $this->fileView->verifyPath($destinationDir, $destinationName); |
|
| 223 | - } catch (\OCP\Files\InvalidPathException $ex) { |
|
| 224 | - throw new InvalidPath($ex->getMessage()); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - try { |
|
| 228 | - $this->fileView->copy($source, $destination); |
|
| 229 | - } catch (StorageNotAvailableException $e) { |
|
| 230 | - throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage()); |
|
| 231 | - } catch (ForbiddenException $ex) { |
|
| 232 | - throw new Forbidden($ex->getMessage(), $ex->getRetry()); |
|
| 233 | - } catch (LockedException $e) { |
|
| 234 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - list($destinationDir,) = \Sabre\Uri\split($destination); |
|
| 238 | - $this->markDirty($destinationDir); |
|
| 239 | - } |
|
| 44 | + /** |
|
| 45 | + * @var \OC\Files\View |
|
| 46 | + */ |
|
| 47 | + protected $fileView; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var \OCP\Files\Mount\IMountManager |
|
| 51 | + */ |
|
| 52 | + protected $mountManager; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Creates the object |
|
| 56 | + */ |
|
| 57 | + public function __construct() { |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @param \Sabre\DAV\INode $rootNode |
|
| 62 | + * @param \OC\Files\View $view |
|
| 63 | + * @param \OCP\Files\Mount\IMountManager $mountManager |
|
| 64 | + */ |
|
| 65 | + public function init(\Sabre\DAV\INode $rootNode, \OC\Files\View $view, \OCP\Files\Mount\IMountManager $mountManager) { |
|
| 66 | + $this->rootNode = $rootNode; |
|
| 67 | + $this->fileView = $view; |
|
| 68 | + $this->mountManager = $mountManager; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * If the given path is a chunked file name, converts it |
|
| 73 | + * to the real file name. Only applies if the OC-CHUNKED header |
|
| 74 | + * is present. |
|
| 75 | + * |
|
| 76 | + * @param string $path chunk file path to convert |
|
| 77 | + * |
|
| 78 | + * @return string path to real file |
|
| 79 | + */ |
|
| 80 | + private function resolveChunkFile($path) { |
|
| 81 | + if (isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
| 82 | + // resolve to real file name to find the proper node |
|
| 83 | + list($dir, $name) = \Sabre\Uri\split($path); |
|
| 84 | + if ($dir === '/' || $dir === '.') { |
|
| 85 | + $dir = ''; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $info = \OC_FileChunking::decodeName($name); |
|
| 89 | + // only replace path if it was really the chunked file |
|
| 90 | + if (isset($info['transferid'])) { |
|
| 91 | + // getNodePath is called for multiple nodes within a chunk |
|
| 92 | + // upload call |
|
| 93 | + $path = $dir . '/' . $info['name']; |
|
| 94 | + $path = ltrim($path, '/'); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + return $path; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Returns the INode object for the requested path |
|
| 102 | + * |
|
| 103 | + * @param string $path |
|
| 104 | + * @return \Sabre\DAV\INode |
|
| 105 | + * @throws InvalidPath |
|
| 106 | + * @throws \Sabre\DAV\Exception\Locked |
|
| 107 | + * @throws \Sabre\DAV\Exception\NotFound |
|
| 108 | + * @throws \Sabre\DAV\Exception\ServiceUnavailable |
|
| 109 | + */ |
|
| 110 | + public function getNodeForPath($path) { |
|
| 111 | + if (!$this->fileView) { |
|
| 112 | + throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup'); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $path = trim($path, '/'); |
|
| 116 | + |
|
| 117 | + if (isset($this->cache[$path])) { |
|
| 118 | + return $this->cache[$path]; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + if ($path) { |
|
| 122 | + try { |
|
| 123 | + $this->fileView->verifyPath($path, basename($path)); |
|
| 124 | + } catch (\OCP\Files\InvalidPathException $ex) { |
|
| 125 | + throw new InvalidPath($ex->getMessage()); |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // Is it the root node? |
|
| 130 | + if (!strlen($path)) { |
|
| 131 | + return $this->rootNode; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + if (pathinfo($path, PATHINFO_EXTENSION) === 'part') { |
|
| 135 | + // read from storage |
|
| 136 | + $absPath = $this->fileView->getAbsolutePath($path); |
|
| 137 | + $mount = $this->fileView->getMount($path); |
|
| 138 | + $storage = $mount->getStorage(); |
|
| 139 | + $internalPath = $mount->getInternalPath($absPath); |
|
| 140 | + if ($storage && $storage->file_exists($internalPath)) { |
|
| 141 | + /** |
|
| 142 | + * @var \OC\Files\Storage\Storage $storage |
|
| 143 | + */ |
|
| 144 | + // get data directly |
|
| 145 | + $data = $storage->getMetaData($internalPath); |
|
| 146 | + $info = new FileInfo($absPath, $storage, $internalPath, $data, $mount); |
|
| 147 | + } else { |
|
| 148 | + $info = null; |
|
| 149 | + } |
|
| 150 | + } else { |
|
| 151 | + // resolve chunk file name to real name, if applicable |
|
| 152 | + $path = $this->resolveChunkFile($path); |
|
| 153 | + |
|
| 154 | + // read from cache |
|
| 155 | + try { |
|
| 156 | + $info = $this->fileView->getFileInfo($path); |
|
| 157 | + } catch (StorageNotAvailableException $e) { |
|
| 158 | + throw new \Sabre\DAV\Exception\ServiceUnavailable('Storage is temporarily not available'); |
|
| 159 | + } catch (StorageInvalidException $e) { |
|
| 160 | + throw new \Sabre\DAV\Exception\NotFound('Storage ' . $path . ' is invalid'); |
|
| 161 | + } catch (LockedException $e) { |
|
| 162 | + throw new \Sabre\DAV\Exception\Locked(); |
|
| 163 | + } catch (ForbiddenException $e) { |
|
| 164 | + throw new \Sabre\DAV\Exception\Forbidden(); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + if (!$info) { |
|
| 169 | + throw new \Sabre\DAV\Exception\NotFound('File with name ' . $path . ' could not be located'); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + if ($info->getType() === 'dir') { |
|
| 173 | + $node = new \OCA\DAV\Connector\Sabre\Directory($this->fileView, $info, $this); |
|
| 174 | + } else { |
|
| 175 | + $node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + $this->cache[$path] = $node; |
|
| 179 | + return $node; |
|
| 180 | + |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Copies a file or directory. |
|
| 185 | + * |
|
| 186 | + * This method must work recursively and delete the destination |
|
| 187 | + * if it exists |
|
| 188 | + * |
|
| 189 | + * @param string $source |
|
| 190 | + * @param string $destination |
|
| 191 | + * @throws FileLocked |
|
| 192 | + * @throws Forbidden |
|
| 193 | + * @throws InvalidPath |
|
| 194 | + * @throws \Exception |
|
| 195 | + * @throws \Sabre\DAV\Exception\Forbidden |
|
| 196 | + * @throws \Sabre\DAV\Exception\Locked |
|
| 197 | + * @throws \Sabre\DAV\Exception\NotFound |
|
| 198 | + * @throws \Sabre\DAV\Exception\ServiceUnavailable |
|
| 199 | + * @return void |
|
| 200 | + */ |
|
| 201 | + public function copy($source, $destination) { |
|
| 202 | + if (!$this->fileView) { |
|
| 203 | + throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup'); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + |
|
| 207 | + $info = $this->fileView->getFileInfo(dirname($destination)); |
|
| 208 | + if ($this->fileView->file_exists($destination)) { |
|
| 209 | + $destinationPermission = $info && $info->isUpdateable(); |
|
| 210 | + } else { |
|
| 211 | + $destinationPermission = $info && $info->isCreatable(); |
|
| 212 | + } |
|
| 213 | + if (!$destinationPermission) { |
|
| 214 | + throw new Forbidden('No permissions to copy object.'); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + // this will trigger existence check |
|
| 218 | + $this->getNodeForPath($source); |
|
| 219 | + |
|
| 220 | + list($destinationDir, $destinationName) = \Sabre\Uri\split($destination); |
|
| 221 | + try { |
|
| 222 | + $this->fileView->verifyPath($destinationDir, $destinationName); |
|
| 223 | + } catch (\OCP\Files\InvalidPathException $ex) { |
|
| 224 | + throw new InvalidPath($ex->getMessage()); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + try { |
|
| 228 | + $this->fileView->copy($source, $destination); |
|
| 229 | + } catch (StorageNotAvailableException $e) { |
|
| 230 | + throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage()); |
|
| 231 | + } catch (ForbiddenException $ex) { |
|
| 232 | + throw new Forbidden($ex->getMessage(), $ex->getRetry()); |
|
| 233 | + } catch (LockedException $e) { |
|
| 234 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + list($destinationDir,) = \Sabre\Uri\split($destination); |
|
| 238 | + $this->markDirty($destinationDir); |
|
| 239 | + } |
|
| 240 | 240 | } |