FutureFile.php 2.4 KB

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