1
0

JailWatcher.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Files\Cache\Wrapper;
  8. use OC\Files\Cache\Watcher;
  9. class JailWatcher extends Watcher {
  10. private string $root;
  11. private Watcher $watcher;
  12. public function __construct(Watcher $watcher, string $root) {
  13. $this->watcher = $watcher;
  14. $this->root = $root;
  15. }
  16. protected function getRoot(): string {
  17. return $this->root;
  18. }
  19. protected function getSourcePath($path): string {
  20. if ($path === '') {
  21. return $this->getRoot();
  22. } else {
  23. return $this->getRoot() . '/' . ltrim($path, '/');
  24. }
  25. }
  26. public function setPolicy($policy) {
  27. $this->watcher->setPolicy($policy);
  28. }
  29. public function getPolicy() {
  30. return $this->watcher->getPolicy();
  31. }
  32. public function checkUpdate($path, $cachedEntry = null) {
  33. return $this->watcher->checkUpdate($this->getSourcePath($path), $cachedEntry);
  34. }
  35. public function update($path, $cachedData) {
  36. $this->watcher->update($this->getSourcePath($path), $cachedData);
  37. }
  38. public function needsUpdate($path, $cachedData) {
  39. return $this->watcher->needsUpdate($this->getSourcePath($path), $cachedData);
  40. }
  41. public function cleanFolder($path) {
  42. $this->watcher->cleanFolder($this->getSourcePath($path));
  43. }
  44. }