summaryrefslogtreecommitdiffstats
path: root/apps/files/ajax/scan.php
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-11-23 00:20:46 +0100
committerRobin Appelman <icewind@owncloud.com>2012-11-23 00:20:46 +0100
commit8fb4dfd2eabcc267725d3c151d93644d6f28f010 (patch)
tree37d36972aedaff185cd79458f42945d895313deb /apps/files/ajax/scan.php
parentad706229f5dbc6382ade61493e9f100a2dc07293 (diff)
downloadnextcloud-server-8fb4dfd2eabcc267725d3c151d93644d6f28f010.tar.gz
nextcloud-server-8fb4dfd2eabcc267725d3c151d93644d6f28f010.zip
use background scanner
Diffstat (limited to 'apps/files/ajax/scan.php')
-rw-r--r--apps/files/ajax/scan.php89
1 files changed, 57 insertions, 32 deletions
diff --git a/apps/files/ajax/scan.php b/apps/files/ajax/scan.php
index 91b20fa8362..53ae4f5ff04 100644
--- a/apps/files/ajax/scan.php
+++ b/apps/files/ajax/scan.php
@@ -1,45 +1,70 @@
<?php
+set_time_limit(0); //scanning can take ages
+session_write_close();
+
+$force = (isset($_GET['force']) and ($_GET['force'] === 'true'));
+$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
+
+$eventSource = new OC_EventSource();
+ScanListener::$eventSource = $eventSource;
+ScanListener::$view = \OC\Files\Filesystem::getView();
-return;
+OC_Hook::connect('\OC\Files\Cache\Scanner', 'scan_folder', 'ScanListener', 'folder');
+OC_Hook::connect('\OC\Files\Cache\Scanner', 'scan_file', 'ScanListener', 'file');
-set_time_limit(0);//scanning can take ages
+$absolutePath = \OC\Files\Filesystem::getView()->getAbsolutePath($dir);
-$force=isset($_GET['force']) and $_GET['force']=='true';
-$dir=isset($_GET['dir'])?$_GET['dir']:'';
-$checkOnly=isset($_GET['checkonly']) and $_GET['checkonly']=='true';
+$mountPoints = \OC\Files\Filesystem::getMountPoints($absolutePath);
+$mountPoints[] = \OC\Files\Filesystem::getMountPoint($absolutePath);
+$mountPoints = array_reverse($mountPoints); //start with the mount point of $dir
-if(!$checkOnly) {
- $eventSource=new OC_EventSource();
+foreach ($mountPoints as $mountPoint) {
+ $storage = \OC\Files\Filesystem::getStorage($mountPoint);
+ error_log('scanning mp '.$mountPoint);
+ ScanListener::$mountPoints[$storage->getId()] = $mountPoint;
+ $scanner = $storage->getScanner();
+ if ($force) {
+ $scanner->scan('');
+ } else {
+ $scanner->backgroundScan();
+ }
}
-session_write_close();
+$eventSource->send('done', ScanListener::$fileCount);
+$eventSource->close();
-//create the file cache if necesary
-if($force or !OC_FileCache::inCache('')) {
- if(!$checkOnly) {
- OCP\DB::beginTransaction();
+class ScanListener {
- if(OC_Cache::isFast()) {
- OC_Cache::clear('fileid/'); //make sure the old fileid's don't mess things up
- }
+ static public $fileCount = 0;
+ static public $lastCount = 0;
- OC_FileCache::scan($dir, $eventSource);
- OC_FileCache::clean();
- OCP\DB::commit();
- $eventSource->send('success', true);
- } else {
- OCP\JSON::success(array('data'=>array('done'=>true)));
- exit;
- }
-} else {
- if($checkOnly) {
- OCP\JSON::success(array('data'=>array('done'=>false)));
- exit;
+ /**
+ * @var \OC\Files\View $view
+ */
+ static public $view;
+
+ /**
+ * @var array $mountPoints map storage ids to mountpoints
+ */
+ static public $mountPoints = array();
+
+ /**
+ * @var \OC_EventSource event source to pass events to
+ */
+ static public $eventSource;
+
+ static function folder($params) {
+ $internalPath = $params['path'];
+ $mountPoint = self::$mountPoints[$params['storage']];
+ $path = self::$view->getRelativePath($mountPoint . $internalPath);
+ self::$eventSource->send('folder', $path);
}
- if(isset($eventSource)) {
- $eventSource->send('success', false);
- } else {
- exit;
+
+ static function file() {
+ self::$fileCount++;
+ if (self::$fileCount > self::$lastCount + 20) { //send a count update every 20 files
+ self::$lastCount = self::$fileCount;
+ self::$eventSource->send('count', self::$fileCount);
+ }
}
}
-$eventSource->close();