protected function scanFiles($user, $path, $verbose, OutputInterface $output, $backgroundScan = false) { $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception # printout and count if ($verbose) { $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFile', function ($path) use($output) { $output->writeln("\tFile <info>{$path}</info>"); $this->filesCounter += 1; if ($this->hasBeenInterrupted()) { throw new \Exception('ctrl-c'); } }); $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFolder', function ($path) use($output) { $output->writeln("\tFolder <info>{$path}</info>"); $this->foldersCounter += 1; if ($this->hasBeenInterrupted()) { throw new \Exception('ctrl-c'); } }); $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use($output) { $output->writeln("Error while scanning, storage not available (" . $e->getMessage() . ")"); }); # count only } else { $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFile', function () use($output) { $this->filesCounter += 1; if ($this->hasBeenInterrupted()) { throw new \Exception('ctrl-c'); } }); $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFolder', function () use($output) { $this->foldersCounter += 1; if ($this->hasBeenInterrupted()) { throw new \Exception('ctrl-c'); } }); } $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFile', function ($path) use($output) { $this->checkScanWarning($path, $output); }); $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFolder', function ($path) use($output) { $this->checkScanWarning($path, $output); }); try { if ($backgroundScan) { $scanner->backgroundScan($path); } else { $scanner->scan($path); } } catch (ForbiddenException $e) { $output->writeln("<error>Home storage for user {$user} not writable</error>"); $output->writeln("Make sure you're running the scan command only as the user the web server runs as"); } catch (\Exception $e) { if ($e->getMessage() !== 'ctrl-c') { $output->writeln('<error>Exception while scanning: ' . $e->getMessage() . "\n" . $e->getTraceAsString() . '</error>'); } return; } }
protected function scanFiles($user, OutputInterface $output) { $scanner = new \OC\Files\Utils\Scanner($user); $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFile', function ($path) use($output) { $output->writeln("Scanning <info>{$path}</info>"); }); $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFolder', function ($path) use($output) { $output->writeln("Scanning <info>{$path}</info>"); }); $scanner->scan(''); }
protected function scanFiles($user, OutputInterface $output) { $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection()); $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFile', function ($path) use($output) { $output->writeln("Scanning <info>{$path}</info>"); }); $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFolder', function ($path) use($output) { $output->writeln("Scanning <info>{$path}</info>"); }); try { $scanner->scan(''); } catch (ForbiddenException $e) { $output->writeln("<error>Home storage for user {$user} not writable</error>"); $output->writeln("Make sure you're running the scan command only as the user the web server runs as"); } }
protected function scanFiles($user, $path, $verbose, OutputInterface $output) { $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); # printout and count if ($verbose) { $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFile', function ($path) use($output) { $output->writeln("Scanning file <info>{$path}</info>"); $this->filesCounter += 1; }); $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFolder', function ($path) use($output) { $output->writeln("Scanning folder <info>{$path}</info>"); $this->foldersCounter += 1; }); $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use($output) { $output->writeln("Error while scanning, storage not available (" . $e->getMessage() . ")"); }); # count only } else { $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFile', function ($path) use($output) { $this->filesCounter += 1; }); $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFolder', function ($path) use($output) { $this->foldersCounter += 1; }); } try { $scanner->scan($path); } catch (ForbiddenException $e) { $output->writeln("<error>Home storage for user {$user} not writable</error>"); $output->writeln("Make sure you're running the scan command only as the user the web server runs as"); } }
public function testNewUser() { $user1 = $this->getUniqueID('user_'); $this->userBackend->createUser($user1, ''); $this->loginAsUser($user1); Filesystem::mkdir('/folder'); Filesystem::mkdir('/folder/subfolder'); Filesystem::file_put_contents('/foo.txt', 'asd'); Filesystem::file_put_contents('/folder/bar.txt', 'fgh'); Filesystem::file_put_contents('/folder/subfolder/qwerty.txt', 'jkl'); $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(), \OC::$server->getLogger()); $scanner->backgroundScan('/'); $newEtags = $this->getEtags($files); // loop over array and use assertSame over assertEquals to prevent false positives foreach ($originalEtags as $file => $originalEtag) { $this->assertSame($originalEtag, $newEtags[$file]); } }
public function testNewUser() { $user1 = uniqid('user_'); $this->userBackend->createUser($user1, ''); \OC_Util::tearDownFS(); \OC_User::setUserId($user1); \OC_Util::setupFS($user1); Filesystem::mkdir('/folder'); Filesystem::mkdir('/folder/subfolder'); Filesystem::file_put_contents('/foo.txt', 'asd'); Filesystem::file_put_contents('/folder/bar.txt', 'fgh'); Filesystem::file_put_contents('/folder/subfolder/qwerty.txt', 'jkl'); $files = array('/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt'); $originalEtags = $this->getEtags($files); $scanner = new \OC\Files\Utils\Scanner($user1); $scanner->backgroundScan('/'); $newEtags = $this->getEtags($files); // loop over array and use assertSame over assertEquals to prevent false positives foreach ($originalEtags as $file => $originalEtag) { $this->assertSame($originalEtag, $newEtags[$file]); } }
$dir = isset($_GET['dir']) ? (string) $_GET['dir'] : ''; if (isset($_GET['users'])) { \OCP\JSON::checkAdminUser(); if ($_GET['users'] === 'all') { $users = OC_User::getUsers(); } else { $users = json_decode($_GET['users']); } } else { $users = array(OC_User::getUser()); } $eventSource = \OC::$server->createEventSource(); $listener = new ScanListener($eventSource); foreach ($users as $user) { $eventSource->send('user', $user); $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection()); $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFile', array($listener, 'file')); $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFolder', array($listener, 'folder')); try { if ($force) { $scanner->scan($dir); } else { $scanner->backgroundScan($dir); } } catch (\Exception $e) { $eventSource->send('error', get_class($e) . ': ' . $e->getMessage()); } } $eventSource->send('done', $listener->getCount()); $eventSource->close(); class ScanListener
public function testScanSubMount() { $uid = $this->getUniqueID(); $this->userBackend->createUser($uid, 'test'); $mountProvider = $this->getMock('\\OCP\\Files\\Config\\IMountProvider'); $storage = new Temporary(array()); $mount = new MountPoint($storage, '/' . $uid . '/files/foo'); $mountProvider->expects($this->any())->method('getMountsForUser')->will($this->returnCallback(function (IUser $user, IStorageFactory $storageFactory) use($mount, $uid) { if ($user->getUID() === $uid) { return [$mount]; } else { return []; } })); \OC::$server->getMountProviderCollection()->registerProvider($mountProvider); $cache = $storage->getCache(); $storage->mkdir('folder'); $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(), \OC::$server->getLogger()); $this->assertFalse($cache->inCache('folder/bar.txt')); $scanner->scan('/' . $uid . '/files/foo'); $this->assertTrue($cache->inCache('folder/bar.txt')); }