示例#1
0
文件: scan.php 项目: kenwi/core
 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");
     }
 }
示例#2
0
文件: scan.php 项目: hjimmy/owncloud
 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('');
 }
示例#3
0
文件: scan.php 项目: Combustible/core
 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");
     }
 }
示例#4
0
    } 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
{
    private $fileCount = 0;
    private $lastCount = 0;
    /**
     * @var \OCP\IEventSource event source to pass events to
示例#5
0
 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'));
 }
示例#6
0
文件: scan.php 项目: matthias-g/core
 protected function scanFiles($user, $path, $verbose, OutputInterface $output)
 {
     $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 exeption
     # 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 ($path) use($output) {
             $this->filesCounter += 1;
             if ($this->hasBeenInterrupted()) {
                 throw new \Exception('ctrl-c');
             }
         });
         $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFolder', function ($path) use($output) {
             $this->foldersCounter += 1;
             if ($this->hasBeenInterrupted()) {
                 throw new \Exception('ctrl-c');
             }
         });
     }
     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");
     } catch (\Exception $e) {
         # exit the function if ctrl-c has been pressed
         return;
     }
 }