more improvements for foldersize

This commit is contained in:
Robin Appelman 2011-04-17 18:18:27 +02:00
parent ec7e338704
commit 871a4b3d4a
1 changed files with 13 additions and 17 deletions

View File

@ -478,6 +478,10 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
* @return int size of folder and it's content * @return int size of folder and it's content
*/ */
public function getFolderSize($path){ public function getFolderSize($path){
$path=str_replace('//','/',$path);
if($this->is_dir($path) and substr($path,-1)!='/'){
$path.='/';
}
$query=OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?"); $query=OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?");
$size=$query->execute(array($path))->fetchAll(); $size=$query->execute(array($path))->fetchAll();
if(count($size)>0){// we already the size, just return it if(count($size)>0){// we already the size, just return it
@ -500,26 +504,19 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
if($this->is_dir($path) and substr($path,-1)!='/'){ if($this->is_dir($path) and substr($path,-1)!='/'){
$path.='/'; $path.='/';
} }
error_log("calc: $path");
$size=0; $size=0;
if ($dh = $this->opendir($path)) { if ($dh = $this->opendir($path)) {
$query=OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?"); while (($filename = readdir($dh)) !== false) {
$hasSize=$query->execute(array($path))->fetchAll(); if($filename!='.' and $filename!='..'){
if(count($hasSize)>0){// yes, update it $subFile=$path.'/'.$filename;
$query=OC_DB::prepare("UPDATE *PREFIX*foldersize SET size=? WHERE path=?"); if($this->is_file($subFile)){
$result=$query->execute(array($size,$path)); $size+=$this->filesize($subFile);
$size+=$hasSize[0]['size']; }else{
}else{// no insert it $size+=$this->getFolderSize($subFile);
while (($filename = readdir($dh)) !== false) {
if($filename!='.' and $filename!='..'){
$subFile=$path.'/'.$filename;
if($this->is_file($subFile)){
$size+=$this->filesize($subFile);
}else{
$size+=$this->calculateFolderSize($subFile);
}
} }
} }
}
if($size>0){
$query=OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)"); $query=OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)");
$result=$query->execute(array($path,$size)); $result=$query->execute(array($path,$size));
} }
@ -539,7 +536,6 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
if($this->is_dir($path) and substr($path,-1)!='/'){ if($this->is_dir($path) and substr($path,-1)!='/'){
$path.='/'; $path.='/';
} }
error_log($path);
$query=OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?"); $query=OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?");
$result=$query->execute(array($path)); $result=$query->execute(array($path));
if($path!='/' and $path!=''){ if($path!='/' and $path!=''){