FutureFile.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\DAV\Upload;
  26. use OCA\DAV\Connector\Sabre\Directory;
  27. use Sabre\DAV\Exception\Forbidden;
  28. use Sabre\DAV\IFile;
  29. /**
  30. * Class FutureFile
  31. *
  32. * The FutureFile is a SabreDav IFile which connects the chunked upload directory
  33. * with the AssemblyStream, who does the final assembly job
  34. *
  35. * @package OCA\DAV\Upload
  36. */
  37. class FutureFile implements \Sabre\DAV\IFile {
  38. /** @var Directory */
  39. private $root;
  40. /** @var string */
  41. private $name;
  42. /**
  43. * @param Directory $root
  44. * @param string $name
  45. */
  46. public function __construct(Directory $root, $name) {
  47. $this->root = $root;
  48. $this->name = $name;
  49. }
  50. /**
  51. * @inheritdoc
  52. */
  53. public function put($data) {
  54. throw new Forbidden('Permission denied to put into this file');
  55. }
  56. /**
  57. * @inheritdoc
  58. */
  59. public function get() {
  60. $nodes = $this->root->getChildren();
  61. return AssemblyStream::wrap($nodes);
  62. }
  63. /**
  64. * @inheritdoc
  65. */
  66. public function getContentType() {
  67. return 'application/octet-stream';
  68. }
  69. /**
  70. * @inheritdoc
  71. */
  72. public function getETag() {
  73. return $this->root->getETag();
  74. }
  75. /**
  76. * @inheritdoc
  77. */
  78. public function getSize() {
  79. $children = $this->root->getChildren();
  80. $sizes = array_map(function ($node) {
  81. /** @var IFile $node */
  82. return $node->getSize();
  83. }, $children);
  84. return array_sum($sizes);
  85. }
  86. /**
  87. * @inheritdoc
  88. */
  89. public function delete() {
  90. $this->root->delete();
  91. }
  92. /**
  93. * @inheritdoc
  94. */
  95. public function getName() {
  96. return $this->name;
  97. }
  98. /**
  99. * @inheritdoc
  100. */
  101. public function setName($name) {
  102. throw new Forbidden('Permission denied to rename this file');
  103. }
  104. /**
  105. * @inheritdoc
  106. */
  107. public function getLastModified() {
  108. return $this->root->getLastModified();
  109. }
  110. }