FutureFile.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. /**
  21. * @param Directory $root
  22. * @param string $name
  23. */
  24. public function __construct(
  25. private Directory $root,
  26. private $name,
  27. ) {
  28. }
  29. /**
  30. * @inheritdoc
  31. */
  32. public function put($data) {
  33. throw new Forbidden('Permission denied to put into this file');
  34. }
  35. /**
  36. * @inheritdoc
  37. */
  38. public function get() {
  39. $nodes = $this->root->getChildren();
  40. return AssemblyStream::wrap($nodes);
  41. }
  42. public function getPath() {
  43. return $this->root->getFileInfo()->getInternalPath() . '/.file';
  44. }
  45. /**
  46. * @inheritdoc
  47. */
  48. public function getContentType() {
  49. return 'application/octet-stream';
  50. }
  51. /**
  52. * @inheritdoc
  53. */
  54. public function getETag() {
  55. return $this->root->getETag();
  56. }
  57. /**
  58. * @inheritdoc
  59. */
  60. public function getSize() {
  61. $children = $this->root->getChildren();
  62. $sizes = array_map(function ($node) {
  63. /** @var IFile $node */
  64. return $node->getSize();
  65. }, $children);
  66. return array_sum($sizes);
  67. }
  68. /**
  69. * @inheritdoc
  70. */
  71. public function delete() {
  72. $this->root->delete();
  73. }
  74. /**
  75. * @inheritdoc
  76. */
  77. public function getName() {
  78. return $this->name;
  79. }
  80. /**
  81. * @inheritdoc
  82. */
  83. public function setName($name) {
  84. throw new Forbidden('Permission denied to rename this file');
  85. }
  86. /**
  87. * @inheritdoc
  88. */
  89. public function getLastModified() {
  90. return $this->root->getLastModified();
  91. }
  92. }