keep encrypted and versioned flag in fscache

This commit is contained in:
Robin Appelman 2011-11-12 01:00:04 +01:00
parent b2f2a87745
commit 024f4375b6
2 changed files with 51 additions and 15 deletions

View File

@ -126,6 +126,22 @@
<length>32</length> <length>32</length>
</field> </field>
<field>
<name>encrypted</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
<length>1</length>
</field>
<field>
<name>versioned</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
<length>1</length>
</field>
<index> <index>
<name>path_index</name> <name>path_index</name>
<unique>true</unique> <unique>true</unique>

View File

@ -38,10 +38,12 @@ class OC_FileCache{
* - mtime * - mtime
* - ctime * - ctime
* - mimetype * - mimetype
* - encrypted
* - versioned
*/ */
public static function get($path){ public static function get($path){
$path=OC_Filesystem::getRoot().$path; $path=OC_Filesystem::getRoot().$path;
$query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size FROM *PREFIX*fscache WHERE path=?'); $query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned FROM *PREFIX*fscache WHERE path=?');
$result=$query->execute(array($path))->fetchRow(); $result=$query->execute(array($path))->fetchRow();
if(is_array($result)){ if(is_array($result)){
return $result; return $result;
@ -60,19 +62,24 @@ class OC_FileCache{
*/ */
public static function put($path,$data){ public static function put($path,$data){
$path=OC_Filesystem::getRoot().$path; $path=OC_Filesystem::getRoot().$path;
if($id=self::getFileId($path)!=-1){
self::update($id,$data);
return;
}
if($path=='/'){ if($path=='/'){
$parent=-1; $parent=-1;
}else{ }else{
$parent=self::getFileId(dirname($path)); $parent=self::getFileId(dirname($path));
} }
$id=self::getFileId($path);
if($id!=-1){
self::update($id,$data);
return;
}
if(!isset($data['encrypted'])){
$data['encrypted']=false;
}
if(!isset($data['versioned'])){
$data['versioned']=false;
}
$mimePart=dirname($data['mimetype']); $mimePart=dirname($data['mimetype']);
$query=OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, size, mtime, ctime, mimetype, mimepart) VALUES(?,?,?,?,?,?,?,?)'); $query=OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, size, mtime, ctime, mimetype, mimepart) VALUES(?,?,?,?,?,?,?,?)');
// echo $path;
// print_r($data);
$query->execute(array($parent,basename($path),$path,$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart)); $query->execute(array($parent,basename($path),$path,$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart));
} }
@ -83,9 +90,21 @@ class OC_FileCache{
* @param array $data * @param array $data
*/ */
private static function update($id,$data){ private static function update($id,$data){
$mimePart=dirname($data['mimetype']); $arguments=array();
$query=OC_DB::prepare('UPDATE *PREFIX*fscache SET size=? ,mtime=? ,ctime=? ,mimetype=? , mimepart=? WHERE id=?'); $queryParts=array();
$query->execute(array($data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$id)); foreach(array('size','mtime','ctime','mimetype','encrypted','versioned') as $attribute){
if(isset($data[$attribute])){
$arguments[]=$data[$attribute];
$queryParts[]=$attribute.'=?';
}
}
if(isset($data['mimetype'])){
$arguments[]=dirname($data['mimetype']);
$queryParts[]='mimepart=?';
}
$arguments[]=$id;
$query=OC_DB::prepare('UPDATE *PREFIX*fscache SET '.implode(' , ',$queryParts).' WHERE id=?');
$query->execute($arguments);
} }
/** /**
@ -137,11 +156,13 @@ class OC_FileCache{
* - mtime * - mtime
* - ctime * - ctime
* - mimetype * - mimetype
* - encrypted
* - versioned
*/ */
public static function getFolderContent($path){ public static function getFolderContent($path){
$path=OC_Filesystem::getRoot().$path; $path=OC_Filesystem::getRoot().$path;
$parent=self::getFileId($path); $parent=self::getFileId($path);
$query=OC_DB::prepare('SELECT name,ctime,mtime,mimetype,size FROM *PREFIX*fscache WHERE parent=?'); $query=OC_DB::prepare('SELECT name,ctime,mtime,mimetype,size,encrypted,versioned FROM *PREFIX*fscache WHERE parent=?');
$result=$query->execute(array($parent))->fetchAll(); $result=$query->execute(array($parent))->fetchAll();
if(is_array($result)){ if(is_array($result)){
return $result; return $result;
@ -201,8 +222,9 @@ class OC_FileCache{
if($mimetype=='httpd/unix-directory'){ if($mimetype=='httpd/unix-directory'){
$size=0; $size=0;
}else{ }else{
if(($id=self::getFileId($fullPath))!=-1){ $id=self::getFileId($fullPath);
$oldInfo=self::get($fullPath); if($id!=-1){
$oldInfo=self::get($path);
$oldSize=$oldInfo['size']; $oldSize=$oldInfo['size'];
}else{ }else{
$oldSize=0; $oldSize=0;
@ -221,7 +243,6 @@ class OC_FileCache{
public static function fileSystemWatcherDelete($params){ public static function fileSystemWatcherDelete($params){
$path=$params['path']; $path=$params['path'];
$fullPath=OC_Filesystem::getRoot().$path; $fullPath=OC_Filesystem::getRoot().$path;
error_log("delete $path");
if(self::getFileId($fullPath)==-1){ if(self::getFileId($fullPath)==-1){
return; return;
} }
@ -258,7 +279,6 @@ class OC_FileCache{
private static function increaseSize($path,$sizeDiff){ private static function increaseSize($path,$sizeDiff){
while(($id=self::getFileId($path))!=-1){ while(($id=self::getFileId($path))!=-1){
$query=OC_DB::prepare('UPDATE *PREFIX*fscache SET size=size+? WHERE id=?'); $query=OC_DB::prepare('UPDATE *PREFIX*fscache SET size=size+? WHERE id=?');
error_log('diff '.$path.' '.$sizeDiff);
$query->execute(array($sizeDiff,$id)); $query->execute(array($sizeDiff,$id));
$path=dirname($path); $path=dirname($path);
} }