aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Cache/Watcher.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Files/Cache/Watcher.php')
-rw-r--r--lib/private/Files/Cache/Watcher.php54
1 files changed, 27 insertions, 27 deletions
diff --git a/lib/private/Files/Cache/Watcher.php b/lib/private/Files/Cache/Watcher.php
index 19e17e60959..f1de5d3cfb8 100644
--- a/lib/private/Files/Cache/Watcher.php
+++ b/lib/private/Files/Cache/Watcher.php
@@ -1,30 +1,10 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Daniel Jagszent <daniel@jagszent.de>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
namespace OC\Files\Cache;
use OCP\Files\Cache\ICacheEntry;
@@ -53,6 +33,9 @@ class Watcher implements IWatcher {
*/
protected $scanner;
+ /** @var callable[] */
+ protected $onUpdate = [];
+
/**
* @param \OC\Files\Storage\Storage $storage
*/
@@ -89,7 +72,14 @@ class Watcher implements IWatcher {
}
if ($cachedEntry === false || $this->needsUpdate($path, $cachedEntry)) {
$this->update($path, $cachedEntry);
- return true;
+
+ if ($cachedEntry === false) {
+ return true;
+ } else {
+ // storage backends can sometimes return false positives, only return true if the scanner actually found a change
+ $newEntry = $this->cache->get($path);
+ return $newEntry->getStorageMTime() > $cachedEntry->getStorageMTime();
+ }
} else {
return false;
}
@@ -113,6 +103,9 @@ class Watcher implements IWatcher {
if ($this->cache instanceof Cache) {
$this->cache->correctFolderSize($path);
}
+ foreach ($this->onUpdate as $callback) {
+ $callback($path);
+ }
}
/**
@@ -123,9 +116,9 @@ class Watcher implements IWatcher {
* @return bool
*/
public function needsUpdate($path, $cachedData) {
- if ($this->watchPolicy === self::CHECK_ALWAYS or ($this->watchPolicy === self::CHECK_ONCE and array_search($path, $this->checkedPaths) === false)) {
+ if ($this->watchPolicy === self::CHECK_ALWAYS or ($this->watchPolicy === self::CHECK_ONCE and !in_array($path, $this->checkedPaths))) {
$this->checkedPaths[] = $path;
- return $this->storage->hasUpdated($path, $cachedData['storage_mtime']);
+ return $cachedData['storage_mtime'] === null || $this->storage->hasUpdated($path, $cachedData['storage_mtime']);
}
return false;
}
@@ -143,4 +136,11 @@ class Watcher implements IWatcher {
}
}
}
+
+ /**
+ * register a callback to be called whenever the watcher triggers and update
+ */
+ public function onUpdate(callable $callback): void {
+ $this->onUpdate[] = $callback;
+ }
}