Skip to content

Commit bd677f6

Browse files
icewind1991artonge
authored andcommitted
background scan the source storage when a background scan on a storage jail is triggered
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 016f992 commit bd677f6

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

lib/private/Files/Cache/Scanner.php

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
use Doctrine\DBAL\Exception;
4040
use OC\Files\Filesystem;
41+
use OC\Files\Storage\Wrapper\Jail;
4142
use OC\Files\Storage\Wrapper\Encoding;
4243
use OC\Hooks\BasicEmitter;
4344
use OCP\Files\Cache\IScanner;
@@ -510,19 +511,31 @@ public static function isPartialFile($file) {
510511
* walk over any folders that are not fully scanned yet and scan them
511512
*/
512513
public function backgroundScan() {
513-
if (!$this->cache->inCache('')) {
514-
$this->runBackgroundScanJob(function () {
515-
$this->scan('', self::SCAN_RECURSIVE, self::REUSE_ETAG);
516-
}, '');
514+
if ($this->storage->instanceOfStorage(Jail::class)) {
515+
// for jail storage wrappers (shares, groupfolders) we run the background scan on the source storage
516+
// this is mainly done because the jail wrapper doesn't implement `getIncomplete` (because it would be inefficient).
517+
//
518+
// Running the scan on the source storage might scan more than "needed", but the unscanned files outside the jail will
519+
// have to be scanned at some point anyway.
520+
$unJailedScanner = $this->storage->getUnjailedStorage()->getScanner();
521+
$unJailedScanner->backgroundScan();
517522
} else {
518-
$lastPath = null;
519-
while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) {
520-
$this->runBackgroundScanJob(function () use ($path) {
521-
$this->scan($path, self::SCAN_RECURSIVE_INCOMPLETE, self::REUSE_ETAG | self::REUSE_SIZE);
522-
}, $path);
523-
// FIXME: this won't proceed with the next item, needs revamping of getIncomplete()
524-
// to make this possible
525-
$lastPath = $path;
523+
if (!$this->cache->inCache('')) {
524+
// if the storage isn't in the cache yet, just scan the root completely
525+
$this->runBackgroundScanJob(function () {
526+
$this->scan('', self::SCAN_RECURSIVE, self::REUSE_ETAG);
527+
}, '');
528+
} else {
529+
$lastPath = null;
530+
// find any path marked as unscanned and run the scanner until no more paths are unscanned (or we get stuck)
531+
while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) {
532+
$this->runBackgroundScanJob(function () use ($path) {
533+
$this->scan($path, self::SCAN_RECURSIVE_INCOMPLETE, self::REUSE_ETAG | self::REUSE_SIZE);
534+
}, $path);
535+
// FIXME: this won't proceed with the next item, needs revamping of getIncomplete()
536+
// to make this possible
537+
$lastPath = $path;
538+
}
526539
}
527540
}
528541
}

lib/private/Files/Utils/Scanner.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,6 @@ public function backgroundScan($dir) {
167167
continue;
168168
}
169169

170-
// don't scan received local shares, these can be scanned when scanning the owner's storage
171-
if ($storage->instanceOfStorage(SharedStorage::class)) {
172-
continue;
173-
}
174170
$scanner = $storage->getScanner();
175171
$this->attachListener($mount);
176172

0 commit comments

Comments
 (0)