FutureFile.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 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. public function __construct(Directory $root, $name) {
  46. $this->root = $root;
  47. $this->name = $name;
  48. }
  49. /**
  50. * @inheritdoc
  51. */
  52. public function put($data) {
  53. throw new Forbidden('Permission denied to put into this file');
  54. }
  55. /**
  56. * @inheritdoc
  57. */
  58. public function get() {
  59. $nodes = $this->root->getChildren();
  60. return AssemblyStream::wrap($nodes);
  61. }
  62. public function getPath() {
  63. return $this->root->getFileInfo()->getInternalPath() . '/.file';
  64. }
  65. /**
  66. * @inheritdoc
  67. */
  68. public function getContentType() {
  69. return 'application/octet-stream';
  70. }
  71. /**
  72. * @inheritdoc
  73. */
  74. public function getETag() {
  75. return $this->root->getETag();
  76. }
  77. /**
  78. * @inheritdoc
  79. */
  80. public function getSize() {
  81. $children = $this->root->getChildren();
  82. $sizes = array_map(function ($node) {
  83. /** @var IFile $node */
  84. return $node->getSize();
  85. }, $children);
  86. return array_sum($sizes);
  87. }
  88. /**
  89. * @inheritdoc
  90. */
  91. public function delete() {
  92. $this->root->delete();
  93. }
  94. /**
  95. * @inheritdoc
  96. */
  97. public function getName() {
  98. return $this->name;
  99. }
  100. /**
  101. * @inheritdoc
  102. */
  103. public function setName($name) {
  104. throw new Forbidden('Permission denied to rename this file');
  105. }
  106. /**
  107. * @inheritdoc
  108. */
  109. public function getLastModified() {
  110. return $this->root->getLastModified();
  111. }
  112. }