@@ -64,340 +64,340 @@ |
||
| 64 | 64 | * @package OC\Files\Node |
| 65 | 65 | */ |
| 66 | 66 | class Root extends Folder implements IRootFolder { |
| 67 | - /** @var Manager */ |
|
| 68 | - private $mountManager; |
|
| 69 | - /** @var PublicEmitter */ |
|
| 70 | - private $emitter; |
|
| 71 | - /** @var null|\OC\User\User */ |
|
| 72 | - private $user; |
|
| 73 | - /** @var CappedMemoryCache */ |
|
| 74 | - private $userFolderCache; |
|
| 75 | - /** @var IUserMountCache */ |
|
| 76 | - private $userMountCache; |
|
| 77 | - /** @var ILogger */ |
|
| 78 | - private $logger; |
|
| 79 | - /** @var IUserManager */ |
|
| 80 | - private $userManager; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @param \OC\Files\Mount\Manager $manager |
|
| 84 | - * @param \OC\Files\View $view |
|
| 85 | - * @param \OC\User\User|null $user |
|
| 86 | - * @param IUserMountCache $userMountCache |
|
| 87 | - * @param ILogger $logger |
|
| 88 | - * @param IUserManager $userManager |
|
| 89 | - */ |
|
| 90 | - public function __construct($manager, |
|
| 91 | - $view, |
|
| 92 | - $user, |
|
| 93 | - IUserMountCache $userMountCache, |
|
| 94 | - ILogger $logger, |
|
| 95 | - IUserManager $userManager) { |
|
| 96 | - parent::__construct($this, $view, ''); |
|
| 97 | - $this->mountManager = $manager; |
|
| 98 | - $this->user = $user; |
|
| 99 | - $this->emitter = new PublicEmitter(); |
|
| 100 | - $this->userFolderCache = new CappedMemoryCache(); |
|
| 101 | - $this->userMountCache = $userMountCache; |
|
| 102 | - $this->logger = $logger; |
|
| 103 | - $this->userManager = $userManager; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Get the user for which the filesystem is setup |
|
| 108 | - * |
|
| 109 | - * @return \OC\User\User |
|
| 110 | - */ |
|
| 111 | - public function getUser() { |
|
| 112 | - return $this->user; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @param string $scope |
|
| 117 | - * @param string $method |
|
| 118 | - * @param callable $callback |
|
| 119 | - */ |
|
| 120 | - public function listen($scope, $method, callable $callback) { |
|
| 121 | - $this->emitter->listen($scope, $method, $callback); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @param string $scope optional |
|
| 126 | - * @param string $method optional |
|
| 127 | - * @param callable $callback optional |
|
| 128 | - */ |
|
| 129 | - public function removeListener($scope = null, $method = null, callable $callback = null) { |
|
| 130 | - $this->emitter->removeListener($scope, $method, $callback); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @param string $scope |
|
| 135 | - * @param string $method |
|
| 136 | - * @param Node[] $arguments |
|
| 137 | - */ |
|
| 138 | - public function emit($scope, $method, $arguments = []) { |
|
| 139 | - $this->emitter->emit($scope, $method, $arguments); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @param \OC\Files\Storage\Storage $storage |
|
| 144 | - * @param string $mountPoint |
|
| 145 | - * @param array $arguments |
|
| 146 | - */ |
|
| 147 | - public function mount($storage, $mountPoint, $arguments = []) { |
|
| 148 | - $mount = new MountPoint($storage, $mountPoint, $arguments); |
|
| 149 | - $this->mountManager->addMount($mount); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @param string $mountPoint |
|
| 154 | - * @return \OC\Files\Mount\MountPoint |
|
| 155 | - */ |
|
| 156 | - public function getMount($mountPoint) { |
|
| 157 | - return $this->mountManager->find($mountPoint); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @param string $mountPoint |
|
| 162 | - * @return \OC\Files\Mount\MountPoint[] |
|
| 163 | - */ |
|
| 164 | - public function getMountsIn($mountPoint) { |
|
| 165 | - return $this->mountManager->findIn($mountPoint); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @param string $storageId |
|
| 170 | - * @return \OC\Files\Mount\MountPoint[] |
|
| 171 | - */ |
|
| 172 | - public function getMountByStorageId($storageId) { |
|
| 173 | - return $this->mountManager->findByStorageId($storageId); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @param int $numericId |
|
| 178 | - * @return MountPoint[] |
|
| 179 | - */ |
|
| 180 | - public function getMountByNumericStorageId($numericId) { |
|
| 181 | - return $this->mountManager->findByNumericId($numericId); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @param \OC\Files\Mount\MountPoint $mount |
|
| 186 | - */ |
|
| 187 | - public function unMount($mount) { |
|
| 188 | - $this->mountManager->remove($mount); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * @param string $path |
|
| 193 | - * @throws \OCP\Files\NotFoundException |
|
| 194 | - * @throws \OCP\Files\NotPermittedException |
|
| 195 | - * @return Node |
|
| 196 | - */ |
|
| 197 | - public function get($path) { |
|
| 198 | - $path = $this->normalizePath($path); |
|
| 199 | - if ($this->isValidPath($path)) { |
|
| 200 | - $fullPath = $this->getFullPath($path); |
|
| 201 | - $fileInfo = $this->view->getFileInfo($fullPath); |
|
| 202 | - if ($fileInfo) { |
|
| 203 | - return $this->createNode($fullPath, $fileInfo); |
|
| 204 | - } else { |
|
| 205 | - throw new NotFoundException($path); |
|
| 206 | - } |
|
| 207 | - } else { |
|
| 208 | - throw new NotPermittedException(); |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - //most operations can't be done on the root |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @param string $targetPath |
|
| 216 | - * @throws \OCP\Files\NotPermittedException |
|
| 217 | - * @return \OC\Files\Node\Node |
|
| 218 | - */ |
|
| 219 | - public function rename($targetPath) { |
|
| 220 | - throw new NotPermittedException(); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - public function delete() { |
|
| 224 | - throw new NotPermittedException(); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * @param string $targetPath |
|
| 229 | - * @throws \OCP\Files\NotPermittedException |
|
| 230 | - * @return \OC\Files\Node\Node |
|
| 231 | - */ |
|
| 232 | - public function copy($targetPath) { |
|
| 233 | - throw new NotPermittedException(); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * @param int $mtime |
|
| 238 | - * @throws \OCP\Files\NotPermittedException |
|
| 239 | - */ |
|
| 240 | - public function touch($mtime = null) { |
|
| 241 | - throw new NotPermittedException(); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * @return \OC\Files\Storage\Storage |
|
| 246 | - * @throws \OCP\Files\NotFoundException |
|
| 247 | - */ |
|
| 248 | - public function getStorage() { |
|
| 249 | - throw new NotFoundException(); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * @return string |
|
| 254 | - */ |
|
| 255 | - public function getPath() { |
|
| 256 | - return '/'; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * @return string |
|
| 261 | - */ |
|
| 262 | - public function getInternalPath() { |
|
| 263 | - return ''; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * @return int |
|
| 268 | - */ |
|
| 269 | - public function getId() { |
|
| 270 | - return null; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * @return array |
|
| 275 | - */ |
|
| 276 | - public function stat() { |
|
| 277 | - return null; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * @return int |
|
| 282 | - */ |
|
| 283 | - public function getMTime() { |
|
| 284 | - return null; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * @param bool $includeMounts |
|
| 289 | - * @return int |
|
| 290 | - */ |
|
| 291 | - public function getSize($includeMounts = true) { |
|
| 292 | - return null; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * @return string |
|
| 297 | - */ |
|
| 298 | - public function getEtag() { |
|
| 299 | - return null; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * @return int |
|
| 304 | - */ |
|
| 305 | - public function getPermissions() { |
|
| 306 | - return \OCP\Constants::PERMISSION_CREATE; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * @return bool |
|
| 311 | - */ |
|
| 312 | - public function isReadable() { |
|
| 313 | - return false; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * @return bool |
|
| 318 | - */ |
|
| 319 | - public function isUpdateable() { |
|
| 320 | - return false; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * @return bool |
|
| 325 | - */ |
|
| 326 | - public function isDeletable() { |
|
| 327 | - return false; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * @return bool |
|
| 332 | - */ |
|
| 333 | - public function isShareable() { |
|
| 334 | - return false; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * @return Node |
|
| 339 | - * @throws \OCP\Files\NotFoundException |
|
| 340 | - */ |
|
| 341 | - public function getParent() { |
|
| 342 | - throw new NotFoundException(); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * @return string |
|
| 347 | - */ |
|
| 348 | - public function getName() { |
|
| 349 | - return ''; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Returns a view to user's files folder |
|
| 354 | - * |
|
| 355 | - * @param string $userId user ID |
|
| 356 | - * @return \OCP\Files\Folder |
|
| 357 | - * @throws NoUserException |
|
| 358 | - * @throws NotPermittedException |
|
| 359 | - */ |
|
| 360 | - public function getUserFolder($userId) { |
|
| 361 | - $userObject = $this->userManager->get($userId); |
|
| 362 | - |
|
| 363 | - if (is_null($userObject)) { |
|
| 364 | - $this->logger->error( |
|
| 365 | - sprintf( |
|
| 366 | - 'Backends provided no user object for %s', |
|
| 367 | - $userId |
|
| 368 | - ), |
|
| 369 | - [ |
|
| 370 | - 'app' => 'files', |
|
| 371 | - ] |
|
| 372 | - ); |
|
| 373 | - throw new NoUserException('Backends provided no user object'); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - $userId = $userObject->getUID(); |
|
| 377 | - |
|
| 378 | - if (!$this->userFolderCache->hasKey($userId)) { |
|
| 379 | - \OC\Files\Filesystem::initMountPoints($userId); |
|
| 380 | - |
|
| 381 | - try { |
|
| 382 | - $folder = $this->get('/' . $userId . '/files'); |
|
| 383 | - } catch (NotFoundException $e) { |
|
| 384 | - if (!$this->nodeExists('/' . $userId)) { |
|
| 385 | - $this->newFolder('/' . $userId); |
|
| 386 | - } |
|
| 387 | - $folder = $this->newFolder('/' . $userId . '/files'); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - $this->userFolderCache->set($userId, $folder); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - return $this->userFolderCache->get($userId); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - public function clearCache() { |
|
| 397 | - $this->userFolderCache = new CappedMemoryCache(); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - public function getUserMountCache() { |
|
| 401 | - return $this->userMountCache; |
|
| 402 | - } |
|
| 67 | + /** @var Manager */ |
|
| 68 | + private $mountManager; |
|
| 69 | + /** @var PublicEmitter */ |
|
| 70 | + private $emitter; |
|
| 71 | + /** @var null|\OC\User\User */ |
|
| 72 | + private $user; |
|
| 73 | + /** @var CappedMemoryCache */ |
|
| 74 | + private $userFolderCache; |
|
| 75 | + /** @var IUserMountCache */ |
|
| 76 | + private $userMountCache; |
|
| 77 | + /** @var ILogger */ |
|
| 78 | + private $logger; |
|
| 79 | + /** @var IUserManager */ |
|
| 80 | + private $userManager; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @param \OC\Files\Mount\Manager $manager |
|
| 84 | + * @param \OC\Files\View $view |
|
| 85 | + * @param \OC\User\User|null $user |
|
| 86 | + * @param IUserMountCache $userMountCache |
|
| 87 | + * @param ILogger $logger |
|
| 88 | + * @param IUserManager $userManager |
|
| 89 | + */ |
|
| 90 | + public function __construct($manager, |
|
| 91 | + $view, |
|
| 92 | + $user, |
|
| 93 | + IUserMountCache $userMountCache, |
|
| 94 | + ILogger $logger, |
|
| 95 | + IUserManager $userManager) { |
|
| 96 | + parent::__construct($this, $view, ''); |
|
| 97 | + $this->mountManager = $manager; |
|
| 98 | + $this->user = $user; |
|
| 99 | + $this->emitter = new PublicEmitter(); |
|
| 100 | + $this->userFolderCache = new CappedMemoryCache(); |
|
| 101 | + $this->userMountCache = $userMountCache; |
|
| 102 | + $this->logger = $logger; |
|
| 103 | + $this->userManager = $userManager; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Get the user for which the filesystem is setup |
|
| 108 | + * |
|
| 109 | + * @return \OC\User\User |
|
| 110 | + */ |
|
| 111 | + public function getUser() { |
|
| 112 | + return $this->user; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @param string $scope |
|
| 117 | + * @param string $method |
|
| 118 | + * @param callable $callback |
|
| 119 | + */ |
|
| 120 | + public function listen($scope, $method, callable $callback) { |
|
| 121 | + $this->emitter->listen($scope, $method, $callback); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @param string $scope optional |
|
| 126 | + * @param string $method optional |
|
| 127 | + * @param callable $callback optional |
|
| 128 | + */ |
|
| 129 | + public function removeListener($scope = null, $method = null, callable $callback = null) { |
|
| 130 | + $this->emitter->removeListener($scope, $method, $callback); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @param string $scope |
|
| 135 | + * @param string $method |
|
| 136 | + * @param Node[] $arguments |
|
| 137 | + */ |
|
| 138 | + public function emit($scope, $method, $arguments = []) { |
|
| 139 | + $this->emitter->emit($scope, $method, $arguments); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @param \OC\Files\Storage\Storage $storage |
|
| 144 | + * @param string $mountPoint |
|
| 145 | + * @param array $arguments |
|
| 146 | + */ |
|
| 147 | + public function mount($storage, $mountPoint, $arguments = []) { |
|
| 148 | + $mount = new MountPoint($storage, $mountPoint, $arguments); |
|
| 149 | + $this->mountManager->addMount($mount); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @param string $mountPoint |
|
| 154 | + * @return \OC\Files\Mount\MountPoint |
|
| 155 | + */ |
|
| 156 | + public function getMount($mountPoint) { |
|
| 157 | + return $this->mountManager->find($mountPoint); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @param string $mountPoint |
|
| 162 | + * @return \OC\Files\Mount\MountPoint[] |
|
| 163 | + */ |
|
| 164 | + public function getMountsIn($mountPoint) { |
|
| 165 | + return $this->mountManager->findIn($mountPoint); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @param string $storageId |
|
| 170 | + * @return \OC\Files\Mount\MountPoint[] |
|
| 171 | + */ |
|
| 172 | + public function getMountByStorageId($storageId) { |
|
| 173 | + return $this->mountManager->findByStorageId($storageId); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @param int $numericId |
|
| 178 | + * @return MountPoint[] |
|
| 179 | + */ |
|
| 180 | + public function getMountByNumericStorageId($numericId) { |
|
| 181 | + return $this->mountManager->findByNumericId($numericId); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @param \OC\Files\Mount\MountPoint $mount |
|
| 186 | + */ |
|
| 187 | + public function unMount($mount) { |
|
| 188 | + $this->mountManager->remove($mount); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * @param string $path |
|
| 193 | + * @throws \OCP\Files\NotFoundException |
|
| 194 | + * @throws \OCP\Files\NotPermittedException |
|
| 195 | + * @return Node |
|
| 196 | + */ |
|
| 197 | + public function get($path) { |
|
| 198 | + $path = $this->normalizePath($path); |
|
| 199 | + if ($this->isValidPath($path)) { |
|
| 200 | + $fullPath = $this->getFullPath($path); |
|
| 201 | + $fileInfo = $this->view->getFileInfo($fullPath); |
|
| 202 | + if ($fileInfo) { |
|
| 203 | + return $this->createNode($fullPath, $fileInfo); |
|
| 204 | + } else { |
|
| 205 | + throw new NotFoundException($path); |
|
| 206 | + } |
|
| 207 | + } else { |
|
| 208 | + throw new NotPermittedException(); |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + //most operations can't be done on the root |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @param string $targetPath |
|
| 216 | + * @throws \OCP\Files\NotPermittedException |
|
| 217 | + * @return \OC\Files\Node\Node |
|
| 218 | + */ |
|
| 219 | + public function rename($targetPath) { |
|
| 220 | + throw new NotPermittedException(); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + public function delete() { |
|
| 224 | + throw new NotPermittedException(); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * @param string $targetPath |
|
| 229 | + * @throws \OCP\Files\NotPermittedException |
|
| 230 | + * @return \OC\Files\Node\Node |
|
| 231 | + */ |
|
| 232 | + public function copy($targetPath) { |
|
| 233 | + throw new NotPermittedException(); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * @param int $mtime |
|
| 238 | + * @throws \OCP\Files\NotPermittedException |
|
| 239 | + */ |
|
| 240 | + public function touch($mtime = null) { |
|
| 241 | + throw new NotPermittedException(); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * @return \OC\Files\Storage\Storage |
|
| 246 | + * @throws \OCP\Files\NotFoundException |
|
| 247 | + */ |
|
| 248 | + public function getStorage() { |
|
| 249 | + throw new NotFoundException(); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * @return string |
|
| 254 | + */ |
|
| 255 | + public function getPath() { |
|
| 256 | + return '/'; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * @return string |
|
| 261 | + */ |
|
| 262 | + public function getInternalPath() { |
|
| 263 | + return ''; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * @return int |
|
| 268 | + */ |
|
| 269 | + public function getId() { |
|
| 270 | + return null; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * @return array |
|
| 275 | + */ |
|
| 276 | + public function stat() { |
|
| 277 | + return null; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * @return int |
|
| 282 | + */ |
|
| 283 | + public function getMTime() { |
|
| 284 | + return null; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * @param bool $includeMounts |
|
| 289 | + * @return int |
|
| 290 | + */ |
|
| 291 | + public function getSize($includeMounts = true) { |
|
| 292 | + return null; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * @return string |
|
| 297 | + */ |
|
| 298 | + public function getEtag() { |
|
| 299 | + return null; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * @return int |
|
| 304 | + */ |
|
| 305 | + public function getPermissions() { |
|
| 306 | + return \OCP\Constants::PERMISSION_CREATE; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * @return bool |
|
| 311 | + */ |
|
| 312 | + public function isReadable() { |
|
| 313 | + return false; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * @return bool |
|
| 318 | + */ |
|
| 319 | + public function isUpdateable() { |
|
| 320 | + return false; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * @return bool |
|
| 325 | + */ |
|
| 326 | + public function isDeletable() { |
|
| 327 | + return false; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * @return bool |
|
| 332 | + */ |
|
| 333 | + public function isShareable() { |
|
| 334 | + return false; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * @return Node |
|
| 339 | + * @throws \OCP\Files\NotFoundException |
|
| 340 | + */ |
|
| 341 | + public function getParent() { |
|
| 342 | + throw new NotFoundException(); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * @return string |
|
| 347 | + */ |
|
| 348 | + public function getName() { |
|
| 349 | + return ''; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Returns a view to user's files folder |
|
| 354 | + * |
|
| 355 | + * @param string $userId user ID |
|
| 356 | + * @return \OCP\Files\Folder |
|
| 357 | + * @throws NoUserException |
|
| 358 | + * @throws NotPermittedException |
|
| 359 | + */ |
|
| 360 | + public function getUserFolder($userId) { |
|
| 361 | + $userObject = $this->userManager->get($userId); |
|
| 362 | + |
|
| 363 | + if (is_null($userObject)) { |
|
| 364 | + $this->logger->error( |
|
| 365 | + sprintf( |
|
| 366 | + 'Backends provided no user object for %s', |
|
| 367 | + $userId |
|
| 368 | + ), |
|
| 369 | + [ |
|
| 370 | + 'app' => 'files', |
|
| 371 | + ] |
|
| 372 | + ); |
|
| 373 | + throw new NoUserException('Backends provided no user object'); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + $userId = $userObject->getUID(); |
|
| 377 | + |
|
| 378 | + if (!$this->userFolderCache->hasKey($userId)) { |
|
| 379 | + \OC\Files\Filesystem::initMountPoints($userId); |
|
| 380 | + |
|
| 381 | + try { |
|
| 382 | + $folder = $this->get('/' . $userId . '/files'); |
|
| 383 | + } catch (NotFoundException $e) { |
|
| 384 | + if (!$this->nodeExists('/' . $userId)) { |
|
| 385 | + $this->newFolder('/' . $userId); |
|
| 386 | + } |
|
| 387 | + $folder = $this->newFolder('/' . $userId . '/files'); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + $this->userFolderCache->set($userId, $folder); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + return $this->userFolderCache->get($userId); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + public function clearCache() { |
|
| 397 | + $this->userFolderCache = new CappedMemoryCache(); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + public function getUserMountCache() { |
|
| 401 | + return $this->userMountCache; |
|
| 402 | + } |
|
| 403 | 403 | } |