UploadFolder.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\DAV\Upload;
  24. use OCA\DAV\BackgroundJob\UploadCleanup;
  25. use OCA\DAV\Connector\Sabre\Directory;
  26. use OCP\BackgroundJob\IJobList;
  27. use Sabre\DAV\Exception\Forbidden;
  28. use Sabre\DAV\ICollection;
  29. class UploadFolder implements ICollection {
  30. /** @var Directory */
  31. private $node;
  32. /** @var CleanupService */
  33. private $cleanupService;
  34. function __construct(Directory $node, CleanupService $cleanupService) {
  35. $this->node = $node;
  36. $this->cleanupService = $cleanupService;
  37. }
  38. function createFile($name, $data = null) {
  39. // TODO: verify name - should be a simple number
  40. $this->node->createFile($name, $data);
  41. }
  42. function createDirectory($name) {
  43. throw new Forbidden('Permission denied to create file (filename ' . $name . ')');
  44. }
  45. function getChild($name) {
  46. if ($name === '.file') {
  47. return new FutureFile($this->node, '.file');
  48. }
  49. return $this->node->getChild($name);
  50. }
  51. function getChildren() {
  52. $children = $this->node->getChildren();
  53. $children[] = new FutureFile($this->node, '.file');
  54. return $children;
  55. }
  56. function childExists($name) {
  57. if ($name === '.file') {
  58. return true;
  59. }
  60. return $this->node->childExists($name);
  61. }
  62. function delete() {
  63. $this->node->delete();
  64. // Background cleanup job is not needed anymore
  65. $this->cleanupService->removeJob($this->getName());
  66. }
  67. function getName() {
  68. return $this->node->getName();
  69. }
  70. function setName($name) {
  71. throw new Forbidden('Permission denied to rename this folder');
  72. }
  73. function getLastModified() {
  74. return $this->node->getLastModified();
  75. }
  76. }