foreach ($users as $user) {
$eventSource->send('user', $user);
- $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection());
+ $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', array($listener, 'file'));
try {
if ($force) {
namespace OCA\Files\Command;
use OC\ForbiddenException;
+use OCP\Files\StorageNotAvailableException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
}
protected function scanFiles($user, $path, $quiet, OutputInterface $output) {
- $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection());
+ $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
if (!$quiet) {
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) {
$output->writeln("Scanning file <info>$path</info>");
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) {
$output->writeln("Scanning folder <info>$path</info>");
});
+ $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) {
+ $output->writeln("Error while scanning, storage not available (" . $e->getMessage() . ")");
+ });
}
try {
$scanner->scan($path);
use OC\ForbiddenException;
use OC\Hooks\PublicEmitter;
use OC\Lock\DBLockingProvider;
+use OCP\Files\StorageNotAvailableException;
+use OCP\ILogger;
/**
* Class Scanner
*/
protected $db;
+ /**
+ * @var ILogger
+ */
+ protected $logger;
+
/**
* @param string $user
* @param \OCP\IDBConnection $db
+ * @param ILogger $logger
*/
- public function __construct($user, $db) {
+ public function __construct($user, $db, ILogger $logger) {
+ $this->logger = $logger;
$this->user = $user;
$this->propagator = new ChangePropagator(new View(''));
$this->db = $db;
if (!$isDbLocking) {
$this->db->beginTransaction();
}
- $scanner->scan($relativePath, \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE);
+ try {
+ $scanner->scan($relativePath, \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE);
+ } catch (StorageNotAvailableException $e) {
+ $this->logger->error('Storage ' . $storage->getId() . ' not available');
+ $this->emit('\OC\Files\Utils\Scanner', 'StorageNotAvailable', [$e]);
+ }
if (!$isDbLocking) {
$this->db->commit();
}
$files = array('/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt');
$originalEtags = $this->getEtags($files);
- $scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->getDatabaseConnection());
+ $scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
$scanner->backgroundScan('/');
$newEtags = $this->getEtags($files);
$storage->file_put_contents('foo.txt', 'qwerty');
$storage->file_put_contents('folder/bar.txt', 'qwerty');
- $scanner = new TestScanner('', \OC::$server->getDatabaseConnection());
+ $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
$scanner->addMount($mount);
$scanner->scan('');
$storage->file_put_contents('foo.txt', 'qwerty');
$storage->file_put_contents('folder/bar.txt', 'qwerty');
- $scanner = new TestScanner('', \OC::$server->getDatabaseConnection());
+ $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
$scanner->addMount($mount);
$scanner->scan('');
$storage->file_put_contents('foo.txt', 'qwerty');
$storage->file_put_contents('folder/bar.txt', 'qwerty');
- $scanner = new \OC\Files\Utils\Scanner($uid, \OC::$server->getDatabaseConnection());
+ $scanner = new \OC\Files\Utils\Scanner($uid, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
$this->assertFalse($cache->inCache('folder/bar.txt'));
$scanner->scan('/' . $uid . '/files/foo');
$storage->file_put_contents('foo.txt', 'qwerty');
$storage->file_put_contents('folder/bar.txt', 'qwerty');
- $scanner = new TestScanner('', \OC::$server->getDatabaseConnection());
+ $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
$originalPropagator = $scanner->getPropagator();
$scanner->setPropagator($propagator);
$scanner->addMount($mount);
* @param string $invalidPath
*/
public function testInvalidPathScanning($invalidPath) {
- $scanner = new TestScanner('', \OC::$server->getDatabaseConnection());
+ $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
$scanner->scan($invalidPath);
}
}