NullStorage.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OC\Lockdown\Filesystem;
  7. use Icewind\Streams\IteratorDirectory;
  8. use OC\Files\FileInfo;
  9. use OC\Files\Storage\Common;
  10. use OCP\Files\Cache\ICache;
  11. use OCP\Files\Storage\IStorage;
  12. class NullStorage extends Common {
  13. public function __construct(array $parameters) {
  14. parent::__construct($parameters);
  15. }
  16. public function getId(): string {
  17. return 'null';
  18. }
  19. public function mkdir(string $path): never {
  20. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  21. }
  22. public function rmdir(string $path): never {
  23. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  24. }
  25. public function opendir(string $path): IteratorDirectory {
  26. return new IteratorDirectory([]);
  27. }
  28. public function is_dir(string $path): bool {
  29. return $path === '';
  30. }
  31. public function is_file(string $path): bool {
  32. return false;
  33. }
  34. public function stat(string $path): never {
  35. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  36. }
  37. public function filetype(string $path): string|false {
  38. return ($path === '') ? 'dir' : false;
  39. }
  40. public function filesize(string $path): never {
  41. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  42. }
  43. public function isCreatable(string $path): bool {
  44. return false;
  45. }
  46. public function isReadable(string $path): bool {
  47. return $path === '';
  48. }
  49. public function isUpdatable(string $path): bool {
  50. return false;
  51. }
  52. public function isDeletable(string $path): bool {
  53. return false;
  54. }
  55. public function isSharable(string $path): bool {
  56. return false;
  57. }
  58. public function getPermissions(string $path): int {
  59. return 0;
  60. }
  61. public function file_exists(string $path): bool {
  62. return $path === '';
  63. }
  64. public function filemtime(string $path): int|false {
  65. return ($path === '') ? time() : false;
  66. }
  67. public function file_get_contents(string $path): never {
  68. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  69. }
  70. public function file_put_contents(string $path, mixed $data): never {
  71. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  72. }
  73. public function unlink(string $path): never {
  74. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  75. }
  76. public function rename(string $source, string $target): never {
  77. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  78. }
  79. public function copy(string $source, string $target): never {
  80. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  81. }
  82. public function fopen(string $path, string $mode): never {
  83. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  84. }
  85. public function getMimeType(string $path): never {
  86. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  87. }
  88. public function hash(string $type, string $path, bool $raw = false): never {
  89. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  90. }
  91. public function free_space(string $path): int {
  92. return FileInfo::SPACE_UNKNOWN;
  93. }
  94. public function touch(string $path, ?int $mtime = null): never {
  95. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  96. }
  97. public function getLocalFile(string $path): string|false {
  98. return false;
  99. }
  100. public function hasUpdated(string $path, int $time): bool {
  101. return false;
  102. }
  103. public function getETag(string $path): string {
  104. return '';
  105. }
  106. public function isLocal(): bool {
  107. return false;
  108. }
  109. public function getDirectDownload(string $path): array|false {
  110. return false;
  111. }
  112. public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath, bool $preserveMtime = false): never {
  113. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  114. }
  115. public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): never {
  116. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  117. }
  118. public function test(): bool {
  119. return true;
  120. }
  121. public function getOwner(string $path): string|false {
  122. return false;
  123. }
  124. public function getCache(string $path = '', ?IStorage $storage = null): ICache {
  125. return new NullCache();
  126. }
  127. }