]> source.dussan.org Git - nextcloud-server.git/commitdiff
background scan the source storage when a background scan on a storage jail is triggered
authorRobin Appelman <robin@icewind.nl>
Tue, 16 Nov 2021 17:10:09 +0000 (18:10 +0100)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Thu, 2 Dec 2021 17:47:05 +0000 (17:47 +0000)
Signed-off-by: Robin Appelman <robin@icewind.nl>
apps/files_sharing/lib/Scanner.php
lib/private/Files/Cache/Scanner.php
lib/private/Files/Utils/Scanner.php

index a240d3ffb8f6b3a0fe9334d97322a29be2925458..baab7a862bd1ea5042acb8804170dc5845550561 100644 (file)
@@ -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;
index bdefca01f6fed8c46c06c58794ece2d7627f4583..bd8db2c8a12b3461829fa09b398445e87166973d 100644 (file)
@@ -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;
+                               }
                        }
                }
        }
index faeb31db8cc0d475fc4b97f7e45cd2432ae32209..2e5a25a355bb97cdca3b50f826976adf82f6218d 100644 (file)
@@ -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);