|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | +/** |
| 5 | + * @copyright Copyright (c) 2024 Robin Appelman <[email protected]> |
| 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 | + |
| 24 | +namespace OC\Files\Cache\Wrapper; |
| 25 | + |
| 26 | +use OC\Files\Cache\Watcher; |
| 27 | + |
| 28 | +class JailWatcher extends Watcher { |
| 29 | + private string $root; |
| 30 | + private Watcher $watcher; |
| 31 | + |
| 32 | + public function __construct(Watcher $watcher, string $root) { |
| 33 | + $this->watcher = $watcher; |
| 34 | + $this->root = $root; |
| 35 | + } |
| 36 | + |
| 37 | + protected function getRoot(): string { |
| 38 | + return $this->root; |
| 39 | + } |
| 40 | + |
| 41 | + protected function getSourcePath($path): string { |
| 42 | + if ($path === '') { |
| 43 | + return $this->getRoot(); |
| 44 | + } else { |
| 45 | + return $this->getRoot() . '/' . ltrim($path, '/'); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + public function setPolicy($policy) { |
| 50 | + $this->watcher->setPolicy($policy); |
| 51 | + } |
| 52 | + |
| 53 | + public function getPolicy() { |
| 54 | + return $this->watcher->getPolicy(); |
| 55 | + } |
| 56 | + |
| 57 | + |
| 58 | + public function checkUpdate($path, $cachedEntry = null) { |
| 59 | + return $this->watcher->checkUpdate($this->getSourcePath($path), $cachedEntry); |
| 60 | + } |
| 61 | + |
| 62 | + public function update($path, $cachedData) { |
| 63 | + $this->watcher->update($this->getSourcePath($path), $cachedData); |
| 64 | + } |
| 65 | + |
| 66 | + public function needsUpdate($path, $cachedData) { |
| 67 | + return $this->watcher->needsUpdate($this->getSourcePath($path), $cachedData); |
| 68 | + } |
| 69 | + |
| 70 | + public function cleanFolder($path) { |
| 71 | + $this->watcher->cleanFolder($this->getSourcePath($path)); |
| 72 | + } |
| 73 | + |
| 74 | +} |
0 commit comments