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