summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-04-29 16:11:17 +0200
committerRobin Appelman <icewind@owncloud.com>2012-04-29 16:11:17 +0200
commit4d3ef9a82448da91335059c8c0ae14e46ecbd18a (patch)
treecf65a58d92b7ddf2e7589251048b006d1e55396a
parent84bd83b1dcbafa109517bc1365fde35d411ed634 (diff)
downloadnextcloud-server-4d3ef9a82448da91335059c8c0ae14e46ecbd18a.tar.gz
nextcloud-server-4d3ef9a82448da91335059c8c0ae14e46ecbd18a.zip
improve rescanning folders
-rw-r--r--lib/filecache.php60
1 files changed, 35 insertions, 25 deletions
diff --git a/lib/filecache.php b/lib/filecache.php
index 431470696a6..fce9785f745 100644
--- a/lib/filecache.php
+++ b/lib/filecache.php
@@ -522,30 +522,27 @@ class OC_FileCache{
$view=new OC_FilesystemView(($root=='/')?'':$root);
}
self::scanFile($path,$root);
- if(self::inCache($path)){
- self::updateFolder($path,$root);
- }else{
- $dh=$view->opendir($path.'/');
- $totalSize=0;
- if($dh){
- while (($filename = readdir($dh)) !== false) {
- if($filename != '.' and $filename != '..'){
- $file=$path.'/'.$filename;
- if($view->is_dir($file.'/')){
- self::scan($file,$eventSource,$count,$root);
- }else{
- $totalSize+=self::scanFile($file,$root);
- $count++;
- if($count>$lastSend+25 and $eventSource){
- $lastSend=$count;
- $eventSource->send('scanning',array('file'=>$path,'count'=>$count));
- }
+ $dh=$view->opendir($path.'/');
+ $totalSize=0;
+ if($dh){
+ while (($filename = readdir($dh)) !== false) {
+ if($filename != '.' and $filename != '..'){
+ $file=$path.'/'.$filename;
+ if($view->is_dir($file.'/')){
+ self::scan($file,$eventSource,$count,$root);
+ }else{
+ $totalSize+=self::scanFile($file,$root);
+ $count++;
+ if($count>$lastSend+25 and $eventSource){
+ $lastSend=$count;
+ $eventSource->send('scanning',array('file'=>$path,'count'=>$count));
}
}
}
}
- self::increaseSize($view->getRoot().$path,$totalSize);
}
+ self::cleanFolder($path,$root);
+ self::increaseSize($view->getRoot().$path,$totalSize);
}
/**
@@ -668,7 +665,26 @@ class OC_FileCache{
}
}
}
+
+ self::cleanFolder($path,$root);
+
+ //update the folder last, so we can calculate the size correctly
+ if(!$root){//filesystem hooks are only valid for the default root
+ OC_Hook::emit('OC_Filesystem','post_write',array('path'=>$path));
+ }else{
+ self::fileSystemWatcherWrite(array('path'=>$path),$root);
+ }
+ }
+ /**
+ * delete non existing files from the cache
+ */
+ private static function cleanFolder($path,$root=''){
+ if(!$root){
+ $view=OC_Filesystem::getView();
+ }else{
+ $view=new OC_FilesystemView(($root=='/')?'':$root);
+ }
//check for removed files, not using getFolderContent to prevent loops
$parent=self::getFileId($view->getRoot().$path);
$query=OC_DB::prepare('SELECT name FROM *PREFIX*fscache WHERE parent=?');
@@ -683,12 +699,6 @@ class OC_FileCache{
}
}
}
- //update the folder last, so we can calculate the size correctly
- if(!$root){//filesystem hooks are only valid for the default root
- OC_Hook::emit('OC_Filesystem','post_write',array('path'=>$path));
- }else{
- self::fileSystemWatcherWrite(array('path'=>$path),$root);
- }
}
/**