FutureFile.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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\IFile;
  28. /**
  29. * Class FutureFile
  30. *
  31. * The FutureFile is a SabreDav IFile which connects the chunked upload directory
  32. * with the AssemblyStream, who does the final assembly job
  33. *
  34. * @package OCA\DAV\Upload
  35. */
  36. class FutureFile implements \Sabre\DAV\IFile {
  37. /** @var Directory */
  38. private $root;
  39. /** @var string */
  40. private $name;
  41. /**
  42. * @param Directory $root
  43. * @param string $name
  44. */
  45. function __construct(Directory $root, $name) {
  46. $this->root = $root;
  47. $this->name = $name;
  48. }
  49. /**
  50. * @inheritdoc
  51. */
  52. function put($data) {
  53. throw new Forbidden('Permission denied to put into this file');
  54. }
  55. /**
  56. * @inheritdoc
  57. */
  58. function get() {
  59. $nodes = $this->root->getChildren();
  60. return AssemblyStream::wrap($nodes);
  61. }
  62. /**
  63. * @inheritdoc
  64. */
  65. function getContentType() {
  66. return 'application/octet-stream';
  67. }
  68. /**
  69. * @inheritdoc
  70. */
  71. function getETag() {
  72. return $this->root->getETag();
  73. }
  74. /**
  75. * @inheritdoc
  76. */
  77. function getSize() {
  78. $children = $this->root->getChildren();
  79. $sizes = array_map(function($node) {
  80. /** @var IFile $node */
  81. return $node->getSize();
  82. }, $children);
  83. return array_sum($sizes);
  84. }
  85. /**
  86. * @inheritdoc
  87. */
  88. function delete() {
  89. $this->root->delete();
  90. }
  91. /**
  92. * @inheritdoc
  93. */
  94. function getName() {
  95. return $this->name;
  96. }
  97. /**
  98. * @inheritdoc
  99. */
  100. function setName($name) {
  101. throw new Forbidden('Permission denied to rename this file');
  102. }
  103. /**
  104. * @inheritdoc
  105. */
  106. function getLastModified() {
  107. return $this->root->getLastModified();
  108. }
  109. }