1
0

JailWatcher.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2024 Robin Appelman <robin@icewind.nl>
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace OC\Files\Cache\Wrapper;
  23. use OC\Files\Cache\Watcher;
  24. class JailWatcher extends Watcher {
  25. private string $root;
  26. private Watcher $watcher;
  27. public function __construct(Watcher $watcher, string $root) {
  28. $this->watcher = $watcher;
  29. $this->root = $root;
  30. }
  31. protected function getRoot(): string {
  32. return $this->root;
  33. }
  34. protected function getSourcePath($path): string {
  35. if ($path === '') {
  36. return $this->getRoot();
  37. } else {
  38. return $this->getRoot() . '/' . ltrim($path, '/');
  39. }
  40. }
  41. public function setPolicy($policy) {
  42. $this->watcher->setPolicy($policy);
  43. }
  44. public function getPolicy() {
  45. return $this->watcher->getPolicy();
  46. }
  47. public function checkUpdate($path, $cachedEntry = null) {
  48. return $this->watcher->checkUpdate($this->getSourcePath($path), $cachedEntry);
  49. }
  50. public function update($path, $cachedData) {
  51. $this->watcher->update($this->getSourcePath($path), $cachedData);
  52. }
  53. public function needsUpdate($path, $cachedData) {
  54. return $this->watcher->needsUpdate($this->getSourcePath($path), $cachedData);
  55. }
  56. public function cleanFolder($path) {
  57. $this->watcher->cleanFolder($this->getSourcePath($path));
  58. }
  59. }