start of proper feedback during filessytem scan

remotes/origin/stable4
Robin Appelman 13 years ago
parent 8543e79713
commit ffecc3e434
  1. 9
      files/ajax/scan.php
  2. 12
      files/js/files.js
  3. 6
      lib/filecache.php

@ -2,15 +2,18 @@
require_once '../../lib/base.php'; require_once '../../lib/base.php';
$eventSource=new OC_EventSource();
$force=isset($_GET['force']) and $_GET['force']=='true'; $force=isset($_GET['force']) and $_GET['force']=='true';
$checkOnly=isset($_GET['checkonly']) and $_GET['checkonly']=='true'; $checkOnly=isset($_GET['checkonly']) and $_GET['checkonly']=='true';
//create the file cache if necesary //create the file cache if necesary
if($force or !OC_FileCache::inCache('')){ if($force or !OC_FileCache::inCache('')){
if(!$checkOnly){ if(!$checkOnly){
OC_FileCache::scan(''); OC_FileCache::scan('',false,$eventSource);
} }
OC_JSON::success(array("data" => array( "done" => true))); $eventSource->send('success',true);
}else{ }else{
OC_JSON::success(array("data" => array( "done" => false))); $eventSource->send('success',false);
} }
$eventSource->close();

@ -348,13 +348,17 @@ $(document).ready(function() {
function scanFiles(force){ function scanFiles(force){
force=!!force; //cast to bool force=!!force; //cast to bool
$('#scanning-message').show(); $('#scanning-message').show();
$.get(OC.filePath('files','ajax','scan.php'),{force:force}, function(response) { var scannerEventSource=new OC.EventSource(OC.filePath('files','ajax','scan.php'),{force:force});
if(response && response.data && response.data.done){ scannerEventSource.listen('scanned',function(file){
console.log(file);//TODO: make this into proper feedback
});
scannerEventSource.listen('success',function(success){
if(success){
window.location.reload(); window.location.reload();
}else{ }else{
alert('error') alert('error while scanning');
} }
}, "json"); });
} }
function boolOperationFinished(data, callback) { function boolOperationFinished(data, callback) {

@ -288,8 +288,9 @@ class OC_FileCache{
* recursively scan the filesystem and fill the cache * recursively scan the filesystem and fill the cache
* @param string $path * @param string $path
* @param bool $onlyChilds * @param bool $onlyChilds
* @param OC_EventSource $enventSource
*/ */
public static function scan($path,$onlyChilds=false){//PROBLEM due to the order things are added, all parents are -1 public static function scan($path,$onlyChilds,$eventSource){//PROBLEM due to the order things are added, all parents are -1
$dh=OC_Filesystem::opendir($path); $dh=OC_Filesystem::opendir($path);
$stat=OC_Filesystem::stat($path); $stat=OC_Filesystem::stat($path);
$mimetype=OC_Filesystem::getMimeType($path); $mimetype=OC_Filesystem::getMimeType($path);
@ -305,12 +306,13 @@ class OC_FileCache{
if($filename != '.' and $filename != '..'){ if($filename != '.' and $filename != '..'){
$file=$path.'/'.$filename; $file=$path.'/'.$filename;
if(OC_Filesystem::is_dir($file)){ if(OC_Filesystem::is_dir($file)){
self::scan($file,true); self::scan($file,true,$eventSource);
}else{ }else{
$stat=OC_Filesystem::stat($file); $stat=OC_Filesystem::stat($file);
$mimetype=OC_Filesystem::getMimeType($file); $mimetype=OC_Filesystem::getMimeType($file);
$stat['mimetype']=$mimetype; $stat['mimetype']=$mimetype;
self::put($file,$stat); self::put($file,$stat);
$eventSource->send('scanned',$file);
$totalSize+=$stat['size']; $totalSize+=$stat['size'];
} }
} }

Loading…
Cancel
Save