Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Appelman <icewind1991@gmail.com>2011-11-09 21:41:57 +0400
committerRobin Appelman <icewind1991@gmail.com>2011-11-09 21:41:57 +0400
commit5a6aba1e1114707942c613c2402eed3237b43a21 (patch)
tree5cda68cc0256db5a3b3002fa694026d7d1475128 /lib/filestorage
parent5cc6635eb81a8d76c04ee040a791f51ebbe389ef (diff)
provide caching for file metadata
Diffstat (limited to 'lib/filestorage')
-rw-r--r--lib/filestorage/local.php83
1 files changed, 1 insertions, 82 deletions
diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php
index b5d6023c494..87efdb15ad2 100644
--- a/lib/filestorage/local.php
+++ b/lib/filestorage/local.php
@@ -13,13 +13,11 @@ class OC_Filestorage_Local extends OC_Filestorage{
}
public function mkdir($path){
if($return=mkdir($this->datadir.$path)){
- $this->clearFolderSizeCache($path);
}
return $return;
}
public function rmdir($path){
if($return=rmdir($this->datadir.$path)){
- $this->clearFolderSizeCache($path);
}
return $return;
}
@@ -72,12 +70,10 @@ class OC_Filestorage_Local extends OC_Filestorage{
}
public function file_put_contents($path,$data){
if($return=file_put_contents($this->datadir.$path,$data)){
- $this->clearFolderSizeCache($path);
}
}
public function unlink($path){
$return=$this->delTree($path);
- $this->clearFolderSizeCache($path);
return $return;
}
public function rename($path1,$path2){
@@ -87,8 +83,6 @@ class OC_Filestorage_Local extends OC_Filestorage{
}
if($return=rename($this->datadir.$path1,$this->datadir.$path2)){
- $this->clearFolderSizeCache($path1);
- $this->clearFolderSizeCache($path2);
}
return $return;
}
@@ -101,7 +95,6 @@ class OC_Filestorage_Local extends OC_Filestorage{
$path2.=$source;
}
if($return=copy($this->datadir.$path1,$this->datadir.$path2)){
- $this->clearFolderSizeCache($path2);
}
return $return;
}
@@ -114,12 +107,10 @@ class OC_Filestorage_Local extends OC_Filestorage{
case 'w+':
case 'x+':
case 'a+':
- $this->clearFolderSizeCache($path);
break;
case 'w':
case 'x':
case 'a':
- $this->clearFolderSizeCache($path);
break;
}
}
@@ -182,7 +173,6 @@ class OC_Filestorage_Local extends OC_Filestorage{
$fileStats = stat($tmpFile);
if(rename($tmpFile,$this->datadir.$path)){
touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']);
- $this->clearFolderSizeCache($path);
return true;
}else{
return false;
@@ -198,7 +188,6 @@ class OC_Filestorage_Local extends OC_Filestorage{
if ($item == '.' || $item == '..') continue;
if(is_file($dir.'/'.$item)){
if(unlink($dir.'/'.$item)){
- $this->clearFolderSizeCache($dir);
}
}elseif(is_dir($dir.'/'.$item)){
if (!$this->delTree($dirRelative. "/" . $item)){
@@ -207,7 +196,6 @@ class OC_Filestorage_Local extends OC_Filestorage{
}
}
if($return=rmdir($dir)){
- $this->clearFolderSizeCache($dir);
}
return $return;
}
@@ -247,75 +235,6 @@ class OC_Filestorage_Local extends OC_Filestorage{
* @return int size of folder and it's content
*/
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=?");
- $size=$query->execute(array($path))->fetchAll();
- if(count($size)>0){// we already the size, just return it
- return $size[0]['size'];
- }else{//the size of the folder isn't know, calulate it
- return $this->calculateFolderSize($path);
- }
- }
-
- /**
- * @brief calulate the size of folder and it's content and cache it
- * @param string $path file path
- * @return int size of folder and it's content
- */
- public function calculateFolderSize($path){
- if($this->is_file($path)){
- $path=dirname($path);
- }
- $path=str_replace('//','/',$path);
- if($this->is_dir($path) and substr($path,-1)!='/'){
- $path.='/';
- }
- $size=0;
- if ($dh = $this->opendir($path)) {
- while (($filename = readdir($dh)) !== false) {
- if($filename!='.' and $filename!='..'){
- $subFile=$path.'/'.$filename;
- if($this->is_file($subFile)){
- $size+=$this->filesize($subFile);
- }else{
- $size+=$this->getFolderSize($subFile);
- }
- }
- }
- if($size>0){
- $query=OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)");
- $result=$query->execute(array($path,$size));
- }
- }
- return $size;
- }
-
- /**
- * @brief clear the folder size cache of folders containing a file
- * @param string $path
- */
- public function clearFolderSizeCache($path){
- if($this->is_file($path)){
- $path=dirname($path);
- }
- $path=str_replace('//','/',$path);
- if($this->is_dir($path) and substr($path,-1)!='/'){
- $path.='/';
- }
- $query=OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?");
- $result=$query->execute(array($path));
- if($path!='/' and $path!=''){
- $parts=explode('/',$path);
- //pop empty part
- $part=array_pop($parts);
- if(empty($part)){
- array_pop($parts);
- }
- $parent=implode('/',$parts);
- $this->clearFolderSizeCache($parent);
- }
+ return 0;//depricated, use OC_FileCach instead
}
}