summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-02-21 20:48:14 +0100
committerRobin Appelman <icewind@owncloud.com>2012-02-21 20:48:49 +0100
commitc20319d37701efb9d32c38dd71880739ca75b33f (patch)
tree1f2f523650e24ea0d1cefd02f653cb85eee57c37 /apps/files_encryption
parentd9c7e4c333f858efaaee35d26ea12733d29bd694 (diff)
downloadnextcloud-server-c20319d37701efb9d32c38dd71880739ca75b33f.tar.gz
nextcloud-server-c20319d37701efb9d32c38dd71880739ca75b33f.zip
fix incorrect information in the filecache when using encryption
Diffstat (limited to 'apps/files_encryption')
-rw-r--r--apps/files_encryption/lib/cryptstream.php5
-rw-r--r--apps/files_encryption/lib/proxy.php31
2 files changed, 18 insertions, 18 deletions
diff --git a/apps/files_encryption/lib/cryptstream.php b/apps/files_encryption/lib/cryptstream.php
index 97e0846187d..86583096f1d 100644
--- a/apps/files_encryption/lib/cryptstream.php
+++ b/apps/files_encryption/lib/cryptstream.php
@@ -90,7 +90,6 @@ class OC_CryptStream{
}
public function stream_write($data){
- error_log('write to '. $this->path);
$length=strlen($data);
$written=0;
$currentPos=ftell($this->source);
@@ -148,9 +147,7 @@ class OC_CryptStream{
}
public function stream_close(){
- if(OC_FileCache::inCache($this->path)){
- OC_FileCache::put($this->path,array('encrypted'=>true));
- }
+ OC_FileCache::put($this->path,array('encrypted'=>true));
return fclose($this->source);
}
} \ No newline at end of file
diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php
index c53d567ad10..ed3907cccfe 100644
--- a/apps/files_encryption/lib/proxy.php
+++ b/apps/files_encryption/lib/proxy.php
@@ -38,13 +38,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
if(is_null(self::$blackList)){
self::$blackList=explode(',',OC_Appconfig::getValue('files_encryption','type_blacklist','jpg,png,jpeg,avi,mpg,mpeg,mkv,mp3,oga,ogv,ogg'));
}
- if(isset(self::$metaData[$path])){
- $metadata=self::$metaData[$path];
- }else{
- $metadata=OC_FileCache::get($path);
- self::$metaData[$path]=$metadata;
- }
- if($metadata['encrypted']){
+ if(self::isEncrypted($path)){
return true;
}
$extention=substr($path,strrpos($path,'.')+1);
@@ -62,7 +56,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
if(isset(self::$metaData[$path])){
$metadata=self::$metaData[$path];
}else{
- $metadata=OC_FileCache::get($path);
+ $metadata=OC_FileCache::getCached($path);
self::$metaData[$path]=$metadata;
}
return (bool)$metadata['encrypted'];
@@ -92,14 +86,19 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
fclose($result);
$result=fopen('crypt://'.$path,$meta['mode']);
}elseif(self::shouldEncrypt($path) and $meta['mode']!='r'){
- if(OC_Filesystem::file_exists($path)){
+ if(OC_Filesystem::file_exists($path) and OC_Filesystem::filesize($path)>0){
//first encrypt the target file so we don't end up with a half encrypted file
OC_Log::write('files_encryption','Decrypting '.$path.' before writing',OC_Log::DEBUG);
- if($result){
- fclose($result);
+ $tmp=fopen('php://temp');
+ while(!feof($result)){
+ $chunk=fread($result,8192);
+ if($chunk){
+ fwrite($tmp,$chunk);
+ }
}
- $tmpFile=OC_Filesystem::toTmpFile($path);
- OC_Filesystem::fromTmpFile($tmpFile,$path);
+ fclose($result);
+ OC_Filesystem::file_put_contents($path,$tmp);
+ fclose($tmp);
}
$result=fopen('crypt://'.$path,$meta['mode']);
}
@@ -117,6 +116,10 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
}
public function postGetMimeType($path,$mime){
- return OC_Helper::getMimeType('crypt://'.$path,'w');
+ if((!OC_FileCache::inCache($path) and self::shouldEncrypt($path)) or self::isEncrypted($path)){
+ return OC_Helper::getMimeType('crypt://'.$path,'w');
+ }else{
+ return $mime;
+ }
}
}