diff options
author | Robin Appelman <robin@icewind.nl> | 2021-11-16 18:10:09 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2021-12-02 17:34:58 +0100 |
commit | f5fe887b4b8bfad2f781c9cd7df221e73758ded2 (patch) | |
tree | 23fd7d79311ca4f7031598b222990ccc24ac12f6 | |
parent | f93061e344b5bb92aa8c32dcc9fd68994b8645ef (diff) | |
download | nextcloud-server-f5fe887b4b8bfad2f781c9cd7df221e73758ded2.tar.gz nextcloud-server-f5fe887b4b8bfad2f781c9cd7df221e73758ded2.zip |
background scan the source storage when a background scan on a storage jail is triggered
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r-- | apps/files_sharing/lib/Scanner.php | 1 | ||||
-rw-r--r-- | lib/private/Files/Cache/Scanner.php | 37 | ||||
-rw-r--r-- | lib/private/Files/Utils/Scanner.php | 4 |
3 files changed, 26 insertions, 16 deletions
diff --git a/apps/files_sharing/lib/Scanner.php b/apps/files_sharing/lib/Scanner.php index a240d3ffb8f..baab7a862bd 100644 --- a/apps/files_sharing/lib/Scanner.php +++ b/apps/files_sharing/lib/Scanner.php @@ -22,6 +22,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ + namespace OCA\Files_Sharing; use OC\Files\ObjectStore\NoopScanner; diff --git a/lib/private/Files/Cache/Scanner.php b/lib/private/Files/Cache/Scanner.php index bdefca01f6f..bd8db2c8a12 100644 --- a/lib/private/Files/Cache/Scanner.php +++ b/lib/private/Files/Cache/Scanner.php @@ -37,6 +37,7 @@ namespace OC\Files\Cache; use Doctrine\DBAL\Exception; use OC\Files\Filesystem; +use OC\Files\Storage\Wrapper\Jail; use OC\Files\Storage\Wrapper\Encoding; use OC\Hooks\BasicEmitter; use OCP\Files\Cache\IScanner; @@ -509,19 +510,31 @@ class Scanner extends BasicEmitter implements IScanner { * walk over any folders that are not fully scanned yet and scan them */ public function backgroundScan() { - if (!$this->cache->inCache('')) { - $this->runBackgroundScanJob(function () { - $this->scan('', self::SCAN_RECURSIVE, self::REUSE_ETAG); - }, ''); + if ($this->storage->instanceOfStorage(Jail::class)) { + // for jail storage wrappers (shares, groupfolders) we run the background scan on the source storage + // this is mainly done because the jail wrapper doesn't implement `getIncomplete` (because it would be inefficient). + // + // Running the scan on the source storage might scan more than "needed", but the unscanned files outside the jail will + // have to be scanned at some point anyway. + $unJailedScanner = $this->storage->getUnjailedStorage()->getScanner(); + $unJailedScanner->backgroundScan(); } else { - $lastPath = null; - while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) { - $this->runBackgroundScanJob(function () use ($path) { - $this->scan($path, self::SCAN_RECURSIVE_INCOMPLETE, self::REUSE_ETAG | self::REUSE_SIZE); - }, $path); - // FIXME: this won't proceed with the next item, needs revamping of getIncomplete() - // to make this possible - $lastPath = $path; + if (!$this->cache->inCache('')) { + // if the storage isn't in the cache yet, just scan the root completely + $this->runBackgroundScanJob(function () { + $this->scan('', self::SCAN_RECURSIVE, self::REUSE_ETAG); + }, ''); + } else { + $lastPath = null; + // find any path marked as unscanned and run the scanner until no more paths are unscanned (or we get stuck) + while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) { + $this->runBackgroundScanJob(function () use ($path) { + $this->scan($path, self::SCAN_RECURSIVE_INCOMPLETE, self::REUSE_ETAG | self::REUSE_SIZE); + }, $path); + // FIXME: this won't proceed with the next item, needs revamping of getIncomplete() + // to make this possible + $lastPath = $path; + } } } } diff --git a/lib/private/Files/Utils/Scanner.php b/lib/private/Files/Utils/Scanner.php index faeb31db8cc..2e5a25a355b 100644 --- a/lib/private/Files/Utils/Scanner.php +++ b/lib/private/Files/Utils/Scanner.php @@ -166,10 +166,6 @@ class Scanner extends PublicEmitter { continue; } - // don't scan received local shares, these can be scanned when scanning the owner's storage - if ($storage->instanceOfStorage(SharedStorage::class)) { - continue; - } $scanner = $storage->getScanner(); $this->attachListener($mount); |