NullCache.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, Robin Appelman <robin@icewind.nl>
  4. *
  5. * @author Robin Appelman <robin@icewind.nl>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace OC\Lockdown\Filesystem;
  24. use OC\Files\Cache\CacheEntry;
  25. use OC\Files\Search\SearchComparison;
  26. use OCP\Constants;
  27. use OCP\Files\Cache\ICache;
  28. use OCP\Files\Cache\ICacheEntry;
  29. use OCP\Files\FileInfo;
  30. use OCP\Files\Search\ISearchComparison;
  31. use OCP\Files\Search\ISearchOperator;
  32. use OCP\Files\Search\ISearchQuery;
  33. class NullCache implements ICache {
  34. public function getNumericStorageId() {
  35. return -1;
  36. }
  37. public function get($file) {
  38. return $file !== '' ? null :
  39. new CacheEntry([
  40. 'fileid' => -1,
  41. 'parent' => -1,
  42. 'name' => '',
  43. 'path' => '',
  44. 'size' => '0',
  45. 'mtime' => time(),
  46. 'storage_mtime' => time(),
  47. 'etag' => '',
  48. 'mimetype' => FileInfo::MIMETYPE_FOLDER,
  49. 'mimepart' => 'httpd',
  50. 'permissions' => Constants::PERMISSION_READ
  51. ]);
  52. }
  53. public function getFolderContents($folder) {
  54. return [];
  55. }
  56. public function getFolderContentsById($fileId) {
  57. return [];
  58. }
  59. public function put($file, array $data) {
  60. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  61. }
  62. public function insert($file, array $data) {
  63. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  64. }
  65. public function update($id, array $data) {
  66. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  67. }
  68. public function getId($file) {
  69. return -1;
  70. }
  71. public function getParentId($file) {
  72. return -1;
  73. }
  74. public function inCache($file) {
  75. return $file === '';
  76. }
  77. public function remove($file) {
  78. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  79. }
  80. public function move($source, $target) {
  81. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  82. }
  83. public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
  84. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  85. }
  86. public function getStatus($file) {
  87. return ICache::COMPLETE;
  88. }
  89. public function search($pattern) {
  90. return [];
  91. }
  92. public function searchByMime($mimetype) {
  93. return [];
  94. }
  95. public function searchQuery(ISearchQuery $query) {
  96. return [];
  97. }
  98. public function getIncomplete() {
  99. return [];
  100. }
  101. public function getPathById($id) {
  102. return '';
  103. }
  104. public function normalize($path) {
  105. return $path;
  106. }
  107. public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, string $targetPath): int {
  108. throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
  109. }
  110. public function getQueryFilterForStorage(): ISearchOperator {
  111. return new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'storage', -1);
  112. }
  113. public function getCacheEntryFromSearchResult(ICacheEntry $rawEntry): ?ICacheEntry {
  114. return null;
  115. }
  116. }