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