1
0

FutureFile.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\Upload;
  8. use OCA\DAV\Connector\Sabre\Directory;
  9. use Sabre\DAV\Exception\Forbidden;
  10. use Sabre\DAV\IFile;
  11. /**
  12. * Class FutureFile
  13. *
  14. * The FutureFile is a SabreDav IFile which connects the chunked upload directory
  15. * with the AssemblyStream, who does the final assembly job
  16. *
  17. * @package OCA\DAV\Upload
  18. */
  19. class FutureFile implements \Sabre\DAV\IFile {
  20. /** @var Directory */
  21. private $root;
  22. /** @var string */
  23. private $name;
  24. /**
  25. * @param Directory $root
  26. * @param string $name
  27. */
  28. public function __construct(Directory $root, $name) {
  29. $this->root = $root;
  30. $this->name = $name;
  31. }
  32. /**
  33. * @inheritdoc
  34. */
  35. public function put($data) {
  36. throw new Forbidden('Permission denied to put into this file');
  37. }
  38. /**
  39. * @inheritdoc
  40. */
  41. public function get() {
  42. $nodes = $this->root->getChildren();
  43. return AssemblyStream::wrap($nodes);
  44. }
  45. public function getPath() {
  46. return $this->root->getFileInfo()->getInternalPath() . '/.file';
  47. }
  48. /**
  49. * @inheritdoc
  50. */
  51. public function getContentType() {
  52. return 'application/octet-stream';
  53. }
  54. /**
  55. * @inheritdoc
  56. */
  57. public function getETag() {
  58. return $this->root->getETag();
  59. }
  60. /**
  61. * @inheritdoc
  62. */
  63. public function getSize() {
  64. $children = $this->root->getChildren();
  65. $sizes = array_map(function ($node) {
  66. /** @var IFile $node */
  67. return $node->getSize();
  68. }, $children);
  69. return array_sum($sizes);
  70. }
  71. /**
  72. * @inheritdoc
  73. */
  74. public function delete() {
  75. $this->root->delete();
  76. }
  77. /**
  78. * @inheritdoc
  79. */
  80. public function getName() {
  81. return $this->name;
  82. }
  83. /**
  84. * @inheritdoc
  85. */
  86. public function setName($name) {
  87. throw new Forbidden('Permission denied to rename this file');
  88. }
  89. /**
  90. * @inheritdoc
  91. */
  92. public function getLastModified() {
  93. return $this->root->getLastModified();
  94. }
  95. }