77 */
88namespace OC \Files \Cache ;
99
10+ use OCP \Files \Cache \ICache ;
1011use OCP \Files \Cache \ICacheEntry ;
12+ use OCP \Files \Cache \IScanner ;
1113use OCP \Files \Cache \IWatcher ;
14+ use OCP \Files \Storage \IStorage ;
1215
1316/**
1417 * check the storage backends for updates and change the cache accordingly
@@ -19,27 +22,26 @@ class Watcher implements IWatcher {
1922 protected $ checkedPaths = [];
2023
2124 /**
22- * @var \OC\Files\Storage\Storage $storage
25+ * @var IStorage $storage
2326 */
2427 protected $ storage ;
2528
2629 /**
27- * @var Cache $cache
30+ * @var ICache $cache
2831 */
2932 protected $ cache ;
3033
3134 /**
32- * @var Scanner $scanner ;
35+ * @var IScanner $scanner ;
3336 */
3437 protected $ scanner ;
3538
3639 /** @var callable[] */
3740 protected $ onUpdate = [];
3841
39- /**
40- * @param \OC\Files\Storage\Storage $storage
41- */
42- public function __construct (\OC \Files \Storage \Storage $ storage ) {
42+ protected ?string $ checkFilter = null ;
43+
44+ public function __construct (IStorage $ storage ) {
4345 $ this ->storage = $ storage ;
4446 $ this ->cache = $ storage ->getCache ();
4547 $ this ->scanner = $ storage ->getScanner ();
@@ -52,6 +54,10 @@ public function setPolicy($policy) {
5254 $ this ->watchPolicy = $ policy ;
5355 }
5456
57+ public function setCheckFilter (?string $ filter ): void {
58+ $ this ->checkFilter = $ filter ;
59+ }
60+
5561 /**
5662 * @return int either \OC\Files\Cache\Watcher::CHECK_NEVER, \OC\Files\Cache\Watcher::CHECK_ONCE, \OC\Files\Cache\Watcher::CHECK_ALWAYS
5763 */
@@ -116,6 +122,12 @@ public function update($path, $cachedData) {
116122 * @return bool
117123 */
118124 public function needsUpdate ($ path , $ cachedData ) {
125+ if ($ this ->checkFilter !== null ) {
126+ if (!preg_match ($ this ->checkFilter , $ path )) {
127+ return false ;
128+ }
129+ }
130+
119131 if ($ this ->watchPolicy === self ::CHECK_ALWAYS || ($ this ->watchPolicy === self ::CHECK_ONCE && !in_array ($ path , $ this ->checkedPaths ))) {
120132 $ this ->checkedPaths [] = $ path ;
121133 return $ cachedData ['storage_mtime ' ] === null || $ this ->storage ->hasUpdated ($ path , $ cachedData ['storage_mtime ' ]);
0 commit comments