NullStorage.php 4.2 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($parameters) {
  14. parent::__construct($parameters);
  15. }
  16. public function getId(): string {
  17. return 'null';
  18. }
  19. public function mkdir($path): never {
  20. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  21. }
  22. public function rmdir($path): never {
  23. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  24. }
  25. public function opendir($path): IteratorDirectory {
  26. return new IteratorDirectory([]);
  27. }
  28. public function is_dir($path): bool {
  29. return $path === '';
  30. }
  31. public function is_file($path): bool {
  32. return false;
  33. }
  34. public function stat($path): never {
  35. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  36. }
  37. public function filetype($path): string|false {
  38. return ($path === '') ? 'dir' : false;
  39. }
  40. public function filesize($path): never {
  41. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  42. }
  43. public function isCreatable($path): bool {
  44. return false;
  45. }
  46. public function isReadable($path): bool {
  47. return $path === '';
  48. }
  49. public function isUpdatable($path): bool {
  50. return false;
  51. }
  52. public function isDeletable($path): bool {
  53. return false;
  54. }
  55. public function isSharable($path): bool {
  56. return false;
  57. }
  58. public function getPermissions($path): int {
  59. return 0;
  60. }
  61. public function file_exists($path): bool {
  62. return $path === '';
  63. }
  64. public function filemtime($path): int|false {
  65. return ($path === '') ? time() : false;
  66. }
  67. public function file_get_contents($path): never {
  68. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  69. }
  70. public function file_put_contents($path, $data): never {
  71. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  72. }
  73. public function unlink($path): never {
  74. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  75. }
  76. public function rename($source, $target): never {
  77. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  78. }
  79. public function copy($source, $target): never {
  80. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  81. }
  82. public function fopen($path, $mode): never {
  83. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  84. }
  85. public function getMimeType($path): never {
  86. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  87. }
  88. public function hash($type, $path, $raw = false): never {
  89. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  90. }
  91. public function free_space($path): int {
  92. return FileInfo::SPACE_UNKNOWN;
  93. }
  94. public function touch($path, $mtime = null): never {
  95. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  96. }
  97. public function getLocalFile($path): string|false {
  98. return false;
  99. }
  100. public function hasUpdated($path, $time): bool {
  101. return false;
  102. }
  103. public function getETag($path): string {
  104. return '';
  105. }
  106. public function isLocal(): bool {
  107. return false;
  108. }
  109. public function getDirectDownload($path): array|false {
  110. return false;
  111. }
  112. public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false): never {
  113. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  114. }
  115. public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $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($path): string|false {
  122. return false;
  123. }
  124. public function getCache($path = '', $storage = null): ICache {
  125. return new NullCache();
  126. }
  127. }