Skip to content

Commit 5ea6976

Browse files
authored
Merge pull request #41015 from nextcloud/background-scan-catch-storage-error
continue background scanning different storages if one fails
2 parents 840e8fc + 3066687 commit 5ea6976

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

lib/private/Files/Utils/Scanner.php

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -156,33 +156,37 @@ protected function attachListener($mount) {
156156
public function backgroundScan($dir) {
157157
$mounts = $this->getMounts($dir);
158158
foreach ($mounts as $mount) {
159-
$storage = $mount->getStorage();
160-
if (is_null($storage)) {
161-
continue;
162-
}
159+
try {
160+
$storage = $mount->getStorage();
161+
if (is_null($storage)) {
162+
continue;
163+
}
163164

164-
// don't bother scanning failed storages (shortcut for same result)
165-
if ($storage->instanceOfStorage(FailedStorage::class)) {
166-
continue;
167-
}
165+
// don't bother scanning failed storages (shortcut for same result)
166+
if ($storage->instanceOfStorage(FailedStorage::class)) {
167+
continue;
168+
}
168169

169-
$scanner = $storage->getScanner();
170-
$this->attachListener($mount);
170+
$scanner = $storage->getScanner();
171+
$this->attachListener($mount);
171172

172-
$scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) {
173-
$this->triggerPropagator($storage, $path);
174-
});
175-
$scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) {
176-
$this->triggerPropagator($storage, $path);
177-
});
178-
$scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) {
179-
$this->triggerPropagator($storage, $path);
180-
});
173+
$scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) {
174+
$this->triggerPropagator($storage, $path);
175+
});
176+
$scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) {
177+
$this->triggerPropagator($storage, $path);
178+
});
179+
$scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) {
180+
$this->triggerPropagator($storage, $path);
181+
});
181182

182-
$propagator = $storage->getPropagator();
183-
$propagator->beginBatch();
184-
$scanner->backgroundScan();
185-
$propagator->commitBatch();
183+
$propagator = $storage->getPropagator();
184+
$propagator->beginBatch();
185+
$scanner->backgroundScan();
186+
$propagator->commitBatch();
187+
} catch (\Exception $e) {
188+
$this->logger->error("Error while trying to scan mount as {$mount->getMountPoint()}:" . $e->getMessage(), ['exception' => $e, 'app' => 'files']);
189+
}
186190
}
187191
}
188192

0 commit comments

Comments
 (0)