From e3adbcb7d58d06c2bac8d925930d2deb2ed563ea Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind@owncloud.com>
Date: Sun, 29 Apr 2012 15:09:47 +0200
Subject: [PATCH] remove non existing files from the cache when rescanning a
 folder

---
 lib/filecache.php  | 34 +++++++++++++++++++---------------
 lib/filesystem.php |  1 +
 2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/lib/filecache.php b/lib/filecache.php
index 28a9eb247a..431470696a 100644
--- a/lib/filecache.php
+++ b/lib/filecache.php
@@ -522,26 +522,30 @@ class OC_FileCache{
 			$view=new OC_FilesystemView(($root=='/')?'':$root);
 		}
 		self::scanFile($path,$root);
-		$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));
+		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));
+							}
 						}
 					}
 				}
 			}
+			self::increaseSize($view->getRoot().$path,$totalSize);
 		}
-		self::increaseSize($view->getRoot().$path,$totalSize);
 	}
 
 	/**
diff --git a/lib/filesystem.php b/lib/filesystem.php
index 1b91eabc7c..cac7e8648e 100644
--- a/lib/filesystem.php
+++ b/lib/filesystem.php
@@ -275,6 +275,7 @@ class OC_Filesystem{
 		if(class_exists($class)){
 			return new $class($arguments);
 		}else{
+			OC_Log::write('core','storage backend '.$class.' not found',OC_Log::ERROR);
 			return false;
 		}
 	}
-- 
GitLab