You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FutureFile.php 2.4KB

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